Skip to content

Commit 2f9c96b

Browse files
committed
Test: Convert "_sourcemap" and "preconfig-flat" fixtures to tap.txt
Add support for setting env. This is motivated by the next patch (Make PerfReporter compatible with Node.js) which will use this for another CLI test case.
1 parent b150d51 commit 2f9c96b

File tree

4 files changed

+48
-59
lines changed

4 files changed

+48
-59
lines changed

test/cli/cli-main.js

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,62 +20,6 @@ QUnit.module('CLI Main', () => {
2020
}
2121
);
2222

23-
QUnit.test('preconfig-flat', async assert => {
24-
const command = ['qunit', 'preconfig-flat.js'];
25-
const execution = await execute(command, {
26-
env: {
27-
qunit_config_filter: '!foobar',
28-
qunit_config_seed: 'dummyfirstyes',
29-
qunit_config_testtimeout: '7',
30-
31-
qunit_config_altertitle: 'true',
32-
qunit_config_noglobals: '1',
33-
qunit_config_notrycatch: 'false'
34-
}
35-
});
36-
assert.equal(execution.snapshot, `Running tests with seed: dummyfirstyes
37-
TAP version 13
38-
ok 1 dummy
39-
not ok 2 slow
40-
---
41-
message: Test took longer than 7ms; test timed out.
42-
severity: failed
43-
...
44-
ok 3 config
45-
1..3
46-
# pass 2
47-
# skip 0
48-
# todo 0
49-
# fail 1
50-
51-
# exit code: 1`);
52-
});
53-
54-
// TODO: Move to /test/cli/fixtures/
55-
QUnit.test('normal trace with native source map', async assert => {
56-
const command = ['qunit', 'sourcemap/source.js'];
57-
const execution = await execute(command);
58-
59-
assert.equal(execution.snapshot, `TAP version 13
60-
ok 1 Example > good
61-
not ok 2 Example > bad
62-
---
63-
message: failed
64-
severity: failed
65-
actual : false
66-
expected: true
67-
stack: |
68-
at /qunit/test/cli/fixtures/sourcemap/source.js:7:16
69-
...
70-
1..2
71-
# pass 1
72-
# skip 0
73-
# todo 0
74-
# fail 1
75-
76-
# exit code: 1`);
77-
});
78-
7923
// Skip in code coverage mode, conflicting maps-on-maps change result
8024
QUnit.test.if('trace with native source map', !process.env.NYC_PROCESS_ID, async function (assert) {
8125
const command = ['qunit', 'sourcemap/source.min.js'];
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# name: normal trace with native source map applied
2+
# command: ["qunit","sourcemap/source.js"]
3+
4+
TAP version 13
5+
ok 1 Example > good
6+
not ok 2 Example > bad
7+
---
8+
message: failed
9+
severity: failed
10+
actual : false
11+
expected: true
12+
stack: |
13+
at /qunit/test/cli/fixtures/sourcemap/source.js:7:16
14+
...
15+
1..2
16+
# pass 1
17+
# skip 0
18+
# todo 0
19+
# fail 1
20+
21+
# exit code: 1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# command: ["qunit", "preconfig-flat.js"]
2+
# env: { "qunit_config_filter": "!foobar", "qunit_config_seed": "dummyfirstyes", "qunit_config_testtimeout": 7, "qunit_config_altertitle": "true", "qunit_config_noglobals": 1, "qunit_config_notrycatch": "false" }
3+
4+
Running tests with seed: dummyfirstyes
5+
TAP version 13
6+
ok 1 dummy
7+
not ok 2 slow
8+
---
9+
message: Test took longer than 7ms; test timed out.
10+
severity: failed
11+
...
12+
ok 3 config
13+
1..3
14+
# pass 2
15+
# skip 0
16+
# todo 0
17+
# fail 1
18+
19+
# exit code: 1

test/cli/helpers/fixtures.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const { execute } = require('./execute.js');
77

88
const NAME_DIRECTIVE = '# name: ';
99
const CMD_DIRECTIVE = '# command: ';
10+
const ENV_DIRECTIVE = '# env: ';
1011

1112
async function parseFixture (file) {
1213
const contents = await fsPromises.readFile(file, 'utf8');
@@ -17,12 +18,16 @@ async function parseFixture (file) {
1718
if (!lines[0].startsWith(CMD_DIRECTIVE)) {
1819
throw new Error(`Missing command declaration in ${path.basename(file)}`);
1920
}
20-
const command = JSON.parse(lines[0].slice(CMD_DIRECTIVE.length));
21+
const command = JSON.parse(lines.shift().slice(CMD_DIRECTIVE.length));
22+
const env = (lines[0].startsWith(ENV_DIRECTIVE))
23+
? JSON.parse(lines.shift().slice(ENV_DIRECTIVE.length))
24+
: undefined;
2125

2226
return {
2327
name,
2428
command,
25-
expected: lines.slice(1).join('\n').trim()
29+
env,
30+
expected: lines.join('\n').trim()
2631
};
2732
}
2833

@@ -32,7 +37,7 @@ function readFixtures (dir) {
3237
for (const file of glob('*.tap.txt', { cwd: dir, absolute: true })) {
3338
fixtures[path.basename(file, '.tap.txt')] = async function runFixture () {
3439
const fixture = await parseFixture(file);
35-
const result = await execute(fixture.command);
40+
const result = await execute(fixture.command, { env: fixture.env });
3641
return {
3742
name: fixture.name,
3843
expected: fixture.expected,

0 commit comments

Comments
 (0)