Skip to content

Commit b154612

Browse files
authored
Updates to our self-hosted tests
* Add debug option to pipe stderr from internal tests to stderr * Remove unnecessary ava dependency in our own test fixtures * Recognize uncaught exceptions in our own tests * Sort all stat objects by file & title
1 parent 51fafed commit b154612

File tree

5 files changed

+44
-35
lines changed

5 files changed

+44
-35
lines changed

test/assertions/fixtures/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66
"nonSemVerExperiments": {
77
"likeAssertion": true
88
}
9-
},
10-
"dependencies": {
11-
"ava": "file:../../.."
129
}
1310
}

test/helpers/exec.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ const serialization = process.versions.node >= '12.16.0' ? 'advanced' : 'json';
99

1010
const normalizePath = (root, file) => path.posix.normalize(path.relative(root, file));
1111

12+
const compareStatObjects = (a, b) => {
13+
if (a.file < b.file) {
14+
return -1;
15+
}
16+
17+
if (a.file > b.file) {
18+
return 1;
19+
}
20+
21+
if (a.title < b.title) {
22+
return -1;
23+
}
24+
25+
return 1;
26+
};
27+
1228
exports.fixture = async (...args) => {
1329
const cwd = path.join(path.dirname(test.meta.file), 'fixtures');
1430
const running = execa.node(cliPath, args, {
@@ -19,52 +35,65 @@ exports.fixture = async (...args) => {
1935
serialization
2036
});
2137

38+
// Besides buffering stderr, if this environment variable is set, also pipe
39+
// to stderr. This can be useful when debugging the tests.
40+
if (process.env.DEBUG_TEST_AVA) {
41+
running.stderr.pipe(process.stderr);
42+
}
43+
2244
const errors = new WeakMap();
2345
const stats = {
2446
failed: [],
47+
passed: [],
2548
skipped: [],
49+
uncaughtExceptions: [],
2650
unsavedSnapshots: [],
27-
passed: [],
2851
getError(statObject) {
2952
return errors.get(statObject);
3053
}
3154
};
3255

33-
running.on('message', message => {
56+
running.on('message', statusEvent => {
3457
if (serialization === 'json') {
35-
message = v8.deserialize(Uint8Array.from(message));
58+
statusEvent = v8.deserialize(Uint8Array.from(statusEvent));
3659
}
3760

38-
switch (message.type) {
61+
switch (statusEvent.type) {
3962
case 'selected-test': {
40-
if (message.skip) {
41-
const {title, testFile} = message;
63+
if (statusEvent.skip) {
64+
const {title, testFile} = statusEvent;
4265
stats.skipped.push({title, file: normalizePath(cwd, testFile)});
4366
}
4467

4568
break;
4669
}
4770

4871
case 'snapshot-error': {
49-
const {testFile} = message;
72+
const {testFile} = statusEvent;
5073
stats.unsavedSnapshots.push({file: normalizePath(cwd, testFile)});
5174
break;
5275
}
5376

5477
case 'test-passed': {
55-
const {title, testFile} = message;
78+
const {title, testFile} = statusEvent;
5679
stats.passed.push({title, file: normalizePath(cwd, testFile)});
5780
break;
5881
}
5982

6083
case 'test-failed': {
61-
const {title, testFile} = message;
84+
const {title, testFile} = statusEvent;
6285
const statObject = {title, file: normalizePath(cwd, testFile)};
63-
errors.set(statObject, message.err);
86+
errors.set(statObject, statusEvent.err);
6487
stats.failed.push(statObject);
6588
break;
6689
}
6790

91+
case 'uncaught-exception': {
92+
const {message, name, stack} = statusEvent.err;
93+
stats.uncaughtExceptions.push({message, name, stack});
94+
break;
95+
}
96+
6897
default:
6998
break;
7099
}
@@ -78,20 +107,9 @@ exports.fixture = async (...args) => {
78107
} catch (error) {
79108
throw Object.assign(error, {stats});
80109
} finally {
81-
stats.passed.sort((a, b) => {
82-
if (a.file < b.file) {
83-
return -1;
84-
}
85-
86-
if (a.file > b.file) {
87-
return 1;
88-
}
89-
90-
if (a.title < b.title) {
91-
return -1;
92-
}
93-
94-
return 1;
95-
});
110+
stats.failed.sort(compareStatObjects);
111+
stats.passed.sort(compareStatObjects);
112+
stats.skipped.sort(compareStatObjects);
113+
stats.unsavedSnapshots.sort(compareStatObjects);
96114
}
97115
};

test/snapshot-updates/fixtures/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"files": [
44
"*.js"
55
]
6-
},
7-
"dependencies": {
8-
"ava": "file:../../.."
96
}
107
}

test/test-timeouts/fixtures/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"files": [
44
"*.js"
55
]
6-
},
7-
"dependencies": {
8-
"ava": "file:../../.."
96
}
107
}

xo.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
}
4545
},
4646
{
47-
files: 'test-tap/fixture/**/*.js',
47+
files: ['test-tap/fixture/**/*.js', 'test/**/fixtures/**/*.js'],
4848
rules: {
4949
'import/no-extraneous-dependencies': 'off'
5050
}

0 commit comments

Comments
 (0)