jest-os-detection
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -7,16 +7,17 @@ "use strict"; | ||
exports.patch = patch; | ||
// TODO handle each platform + group of platform | ||
// 'aix', 'darwin', 'freebsd', 'linux', 'openbsd', 'sunos', and 'win32' | ||
const AVAILABLE_PLATFORMS = { | ||
onWindows: 'win32', | ||
onMac: 'darwin', | ||
onLinux: 'linux' | ||
onWindows: ['win32'], | ||
onMac: ['darwin'], | ||
onLinux: ['linux'], | ||
skipWindows: ['linux', 'darwin'], | ||
skipMac: ['linux', 'win32'], | ||
skipLinux: ['darwin', 'win32'] | ||
}; | ||
function patch(currentPlatform) { | ||
function newDefinition(method, expectedPlatform, ...args) { | ||
if (currentPlatform === AVAILABLE_PLATFORMS[expectedPlatform]) { | ||
return method(...args); | ||
function newDefinition(method, expectedPlatform, fallbackImplem = () => {}) { | ||
if (AVAILABLE_PLATFORMS[expectedPlatform] && AVAILABLE_PLATFORMS[expectedPlatform].includes(currentPlatform)) { | ||
return method; | ||
} else { | ||
return () => {}; | ||
return fallbackImplem; | ||
} | ||
@@ -28,18 +29,7 @@ } | ||
[describe, it, test].forEach(method => { | ||
method[platform] = (...args) => { | ||
return newDefinition(method, platform, ...args); | ||
}; | ||
method[platform].each = (...args) => { | ||
return newDefinition(method.each, platform, ...args); | ||
}; | ||
method[platform] = newDefinition((...args) => method(...args), platform); | ||
method[platform].each = newDefinition(method.each, platform, method.skip.each); | ||
['skip', 'only'].forEach(mode => { | ||
method[platform][mode] = (...args) => { | ||
return newDefinition(method[mode], platform, ...args); | ||
}; | ||
method[platform][mode].each = (...args) => { | ||
return newDefinition(method[mode].each, platform, ...args); | ||
}; | ||
method[platform][mode] = newDefinition(method[mode], platform, method.skip); | ||
method[platform][mode] = newDefinition(method[mode], platform, method.skip.each); | ||
}); | ||
@@ -46,0 +36,0 @@ }); |
{ | ||
"name": "jest-os-detection", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Allow to specify on which platform to run jest tests", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -9,2 +9,5 @@ # Jest OS detection | ||
All tests that should not be run on the current | ||
platform will be automatically skipped. | ||
## Install | ||
@@ -63,2 +66,5 @@ | ||
* `<command>.onLinux()` | ||
* `<command>.skipWindows()` | ||
* `<command>.skipMac()` | ||
* `<command>.skipLinux()` | ||
@@ -65,0 +71,0 @@ Supported sub-commands: |
@@ -65,2 +65,8 @@ import { patch } from '../src/patch-jest' | ||
}) | ||
describe.skipLinux('describe.skipLinux', () => { | ||
it('should not be executed', () => { | ||
throw new Error('should not be run') | ||
}) | ||
}) | ||
}) |
@@ -69,2 +69,8 @@ import { patch } from '../src/patch-jest' | ||
}) | ||
describe.skipLinux('describe.skipLinux', () => { | ||
it('should be executed', () => { | ||
expect(1).toBe(1) | ||
}) | ||
}) | ||
}) |
@@ -65,2 +65,8 @@ import { patch } from '../src/patch-jest' | ||
}) | ||
describe.skipLinux('describe.skipLinux', () => { | ||
it('should be executed', () => { | ||
expect(1).toBe(1) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
298407
212
75