forked from qunitjs/qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
146 lines (121 loc) · 4.7 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"use strict";
const co = require( "co" );
const expectedOutput = require( "./fixtures/expected/tap-outputs" );
const execute = require( "./helpers/execute" );
QUnit.module( "CLI Main", function() {
QUnit.test( "defaults to running tests in 'test' directory", co.wrap( function* ( assert ) {
const command = "qunit";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "errors if no test files are found to run", co.wrap( function* ( assert ) {
try {
yield execute( "qunit does-not-exist.js" );
} catch ( e ) {
assert.equal( e.stderr.indexOf( "No files were found matching" ), 0 );
}
} ) );
QUnit.test( "accepts globs for test files to run", co.wrap( function* ( assert ) {
const command = "qunit 'glob/**/*-test.js'";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "runs a single JS file", co.wrap( function* ( assert ) {
const command = "qunit single.js";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "runs multiple JS files", co.wrap( function* ( assert ) {
const command = "qunit single.js double.js";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "runs all JS files in a directory matching an arg", co.wrap( function* ( assert ) {
const command = "qunit test";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "runs multiple types of file paths", co.wrap( function* ( assert ) {
const command = "qunit test single.js 'glob/**/*-test.js'";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
QUnit.test( "logs test files that fail to load properly", co.wrap( function* ( assert ) {
try {
yield execute( "qunit syntax-error/test.js" );
} catch ( e ) {
assert.notEqual( e.stdout.indexOf( "not ok 1 syntax-error/test.js > Failed to load the test file with error:" ), -1 );
assert.notEqual( e.stdout.indexOf( "ReferenceError: varIsNotDefined is not defined" ), -1 );
assert.equal( e.code, 1 );
}
} ) );
QUnit.test( "exit code is 1 when failing tests are present", co.wrap( function* ( assert ) {
try {
yield execute( "qunit fail/*.js" );
} catch ( e ) {
assert.equal( e.code, 1 );
}
} ) );
QUnit.test( "exit code is 1 when no tests are run", co.wrap( function* ( assert ) {
try {
yield execute( "qunit no-tests" );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "Error: No tests were run\n" );
}
} ) );
QUnit.test( "exit code is 1 when no tests exit before done", co.wrap( function* ( assert ) {
const command = "qunit hanging-test";
try {
yield execute( command );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, expectedOutput[ command ] );
}
} ) );
QUnit.test( "unhandled rejections fail tests", co.wrap( function* ( assert ) {
const command = "qunit unhandled-rejection.js";
try {
const result = yield execute( command );
assert.pushResult( {
result: false,
actual: result.stdout
} );
} catch ( e ) {
assert.equal( e.code, 1 );
assert.equal( e.stderr, "" );
assert.equal( e.stdout, expectedOutput[ command ] );
}
} ) );
QUnit.module( "filter", function() {
QUnit.test( "can properly filter tests", co.wrap( function* ( assert ) {
const command = "qunit --filter 'single' test single.js 'glob/**/*-test.js'";
const equivalentCommand = "qunit single.js";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ equivalentCommand ] );
} ) );
} );
QUnit.module( "seed", function() {
QUnit.test( "can properly seed tests", co.wrap( function* ( assert ) {
const command = "qunit --seed 's33d' test single.js 'glob/**/*-test.js'";
const execution = yield execute( command );
assert.equal( execution.code, 0 );
assert.equal( execution.stderr, "" );
assert.equal( execution.stdout, expectedOutput[ command ] );
} ) );
} );
} );