-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
75 lines (69 loc) · 2.3 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os from 'os';
import test from 'ava';
import semver from 'semver';
import testEngine from './';
test('is supported', async (t) => {
const isSupported = await testEngine();
t.is(typeof isSupported, 'boolean');
t.true(isSupported);
await t.notThrows(testEngine.assert());
});
test('detailed report', async (t) => {
const engine = await testEngine.detail();
t.truthy(engine);
t.is(typeof engine, 'object');
const ownProps = Object.getOwnPropertyNames(engine);
t.is(ownProps.length, 2);
t.true(ownProps.includes('allSatisfied'));
t.true(ownProps.includes('satisfied'));
t.deepEqual(ownProps, [
'allSatisfied',
'satisfied'
]);
t.true(engine.allSatisfied);
t.false('notSatisfied' in engine);
const { satisfied } = engine;
t.truthy(satisfied);
t.is(typeof satisfied, 'object');
t.true(Object.prototype.hasOwnProperty.call(satisfied, 'node'));
t.truthy(satisfied.node);
t.is(typeof satisfied.node, 'object');
t.truthy(satisfied.node.actual);
t.is(typeof satisfied.node.actual, 'string');
t.truthy(satisfied.node.expected);
t.is(typeof satisfied.node.expected, 'string');
t.true(semver.satisfies(satisfied.node.actual, satisfied.node.expected));
});
test('custom cwd', async (t) => {
const nonPkgDir = os.tmpdir();
const isSupported = await testEngine(nonPkgDir, {
node : '0.0.1',
npm : '0.0.1'
});
t.true(isSupported);
const engine = await testEngine.detail(nonPkgDir, {
node : '0.0.1',
npm : '0.0.1'
});
t.truthy(engine);
t.is(typeof engine, 'object');
t.true(engine.allSatisfied);
t.deepEqual(engine, {
allSatisfied : true
});
});
test('.assert() returns report if supported', async (t) => {
const engine = await t.notThrows(testEngine.assert());
t.truthy(engine);
t.is(typeof engine, 'object');
t.true(engine.allSatisfied);
t.false('notSatisfied' in engine);
});
test('.assert() throws if unsupported', async (t) => {
const err = await t.throws(testEngine.assert(null, { node : '0.10.0' }), RangeError);
t.truthy(err.engine);
t.is(typeof err.engine, 'object');
t.true(Object.prototype.hasOwnProperty.call(err, 'engine'));
t.false(err.engine.allSatisfied);
t.false('satisfied' in err.engine);
});