2019-09-21 10:41:21 +09:00
|
|
|
import getOS from '../src/get-os';
|
|
|
|
|
|
|
|
|
|
describe('getOS', () => {
|
2022-10-13 23:13:33 -05:00
|
|
|
const groups = [
|
|
|
|
|
{
|
|
|
|
|
condition: 'when hugo version < 0.102.0',
|
|
|
|
|
conventions: {
|
|
|
|
|
arch: {
|
|
|
|
|
darwinUniversal: false,
|
|
|
|
|
dropped32BitSupport: false,
|
|
|
|
|
standardizedNaming: false,
|
|
|
|
|
},
|
|
|
|
|
os: {
|
|
|
|
|
renamedMacOS: false,
|
|
|
|
|
downcasedAll: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tests: [
|
|
|
|
|
{ os: 'linux', expected: 'Linux' },
|
|
|
|
|
{ os: 'darwin', expected: 'macOS' },
|
|
|
|
|
{ os: 'win32', expected: 'Windows' },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
condition: 'when hugo version === 0.102.z',
|
|
|
|
|
conventions: {
|
|
|
|
|
arch: {
|
|
|
|
|
darwinUniversal: true,
|
|
|
|
|
dropped32BitSupport: true,
|
|
|
|
|
standardizedNaming: false,
|
|
|
|
|
},
|
|
|
|
|
os: {
|
|
|
|
|
renamedMacOS: true,
|
|
|
|
|
downcasedAll: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tests: [
|
|
|
|
|
{ os: 'linux', expected: 'Linux' },
|
|
|
|
|
{ os: 'darwin', expected: 'darwin' },
|
|
|
|
|
{ os: 'win32', expected: 'Windows' },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
condition: 'when hugo version >= 0.103.0',
|
|
|
|
|
conventions: {
|
|
|
|
|
arch: {
|
|
|
|
|
darwinUniversal: true,
|
|
|
|
|
dropped32BitSupport: true,
|
|
|
|
|
standardizedNaming: true,
|
|
|
|
|
},
|
|
|
|
|
os: {
|
|
|
|
|
renamedMacOS: true,
|
|
|
|
|
downcasedAll: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
tests: [
|
|
|
|
|
{ os: 'linux', expected: 'linux' },
|
|
|
|
|
{ os: 'darwin', expected: 'darwin' },
|
|
|
|
|
{ os: 'win32', expected: 'windows' },
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
].map(function (group) {
|
|
|
|
|
group.tests = group.tests.map(function (example) {
|
|
|
|
|
return Object.assign(example, {
|
|
|
|
|
toString: function () {
|
|
|
|
|
return `${example.os} returns ${example.expected}`
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
return Object.assign(group, { toString: function () { return group.condition } });
|
|
|
|
|
});
|
2022-10-06 06:47:41 -05:00
|
|
|
|
2022-10-13 23:13:33 -05:00
|
|
|
describe.each(groups)('%s', ({ conventions, tests }) => {
|
|
|
|
|
test.each(tests)('%s', ({ os, expected }) => {
|
|
|
|
|
expect(getOS(os, conventions)).toBe(expected);
|
|
|
|
|
})
|
2019-09-21 10:41:21 +09:00
|
|
|
});
|
|
|
|
|
|
2020-10-12 15:26:57 +09:00
|
|
|
test('exception', () => {
|
2022-10-13 23:13:33 -05:00
|
|
|
const conventions = {
|
|
|
|
|
arch: {
|
|
|
|
|
darwinUniversal: false,
|
|
|
|
|
dropped32BitSupport: false,
|
|
|
|
|
standardizedNaming: false,
|
|
|
|
|
},
|
|
|
|
|
os: {
|
|
|
|
|
renamedMacOS: false,
|
|
|
|
|
downcasedAll: false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-21 10:41:21 +09:00
|
|
|
expect(() => {
|
2022-10-13 23:13:33 -05:00
|
|
|
getOS('centos', conventions);
|
2022-10-06 13:13:28 +00:00
|
|
|
}).toThrow('centos is not supported');
|
2019-09-21 10:41:21 +09:00
|
|
|
});
|
|
|
|
|
});
|