This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
test.js
137 lines (115 loc) · 7.52 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
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
'use strict'
var fs = require('fs-extra');
var exec = require('child_process').exec;
var chai = require('chai');
var expect = chai.expect;
var FAILING_FILE = __dirname + '/../tests/dummy/app/unused.js';
var path = require('path');
describe('ember-cli-eslint', function() {
this.timeout(60000);
afterEach(function() {
fs.removeSync(FAILING_FILE);
});
it('passes if ESLint tests pass', function() {
process.env['NO_GROUPING'] = true;
return emberTest().then(function(result) {
expect(result.error).to.not.exist;
expect(result.stdout)
.to.match(/ok 1 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app\.js: should pass ESLint\r?\n/)
.to.match(/ok 2 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| controllers\/thing\.js: should pass ESLint\r?\n/)
.to.match(/ok 3 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/destroy-app\.js: should pass ESLint\r?\n/)
.to.match(/ok 4 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/module-for-acceptance\.js: should pass ESLint\r?\n/)
.to.match(/ok 5 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/start-app\.js: should pass ESLint\r?\n/)
.to.match(/ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| models\/thing\.js: should pass ESLint\r?\n/)
.to.match(/ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| resolver\.js: should pass ESLint\r?\n/)
.to.match(/ok 8 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| router\.js: should pass ESLint\r?\n/)
.to.match(/ok 9 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| test-helper\.js: should pass ESLint\r?\n/)
.to.not.match(/not ok 10 Chrome [0-9]+\.[0-9]+ \[[0-9]+ ms\] - ESLint \| unused\.js: should pass ESLint\r?\n/);
})
});
it('fails if a ESLint tests fails', function() {
process.env['NO_GROUPING'] = true;
fs.outputFileSync(FAILING_FILE, 'let unused = 6;\n');
return emberTest({ NO_GROUPING: true }).then(function(result) {
expect(result.error).to.exist;
expect(result.stdout)
.to.match(/ok 1 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app\.js: should pass ESLint\r?\n/)
.to.match(/ok 2 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| controllers\/thing\.js: should pass ESLint\r?\n/)
.to.match(/ok 3 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/destroy-app\.js: should pass ESLint\r?\n/)
.to.match(/ok 4 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/module-for-acceptance\.js: should pass ESLint\r?\n/)
.to.match(/ok 5 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| helpers\/start-app\.js: should pass ESLint\r?\n/)
.to.match(/ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| models\/thing\.js: should pass ESLint\r?\n/)
.to.match(/ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| resolver\.js: should pass ESLint\r?\n/)
.to.match(/ok 8 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| router\.js: should pass ESLint\r?\n/)
.to.match(/ok 9 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| test-helper\.js: should pass ESLint\r?\n/)
.to.match(/not ok 10 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| unused\.js: should pass ESLint\r?\n/);
})
});
it('passes if ESLint tests pass (grouped)', function() {
delete process.env['NO_GROUPING'];
return emberTest().then(function(result) {
expect(result.error).to.not.exist;
expect(result.stdout)
.to.match(/ok 1 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: app\.js\r?\n/)
.to.match(/ok 2 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: controllers\/thing\.js\r?\n/)
.to.match(/ok 3 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: models\/thing\.js\r?\n/)
.to.match(/ok 4 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: resolver\.js\r?\n/)
.to.match(/ok 5 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: router\.js\r?\n/)
.to.not.match(/not ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: unused\.js\r?\n/);
expect(result.stdout)
.to.match(/ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/destroy-app\.js\r?\n/)
.to.match(/ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/module-for-acceptance\.js\r?\n/)
.to.match(/ok 8 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/start-app\.js\r?\n/)
.to.match(/ok 9 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: test-helper\.js\r?\n/);
})
});
it('fails if a ESLint tests fails (grouped)', function() {
delete process.env['NO_GROUPING'];
fs.outputFileSync(FAILING_FILE, 'let unused = 6;\n');
return emberTest().then(function(result) {
expect(result.error).to.exist;
expect(result.stdout)
.to.match(/ok 1 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: app\.js\r?\n/)
.to.match(/ok 2 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: controllers\/thing\.js\r?\n/)
.to.match(/ok 3 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: models\/thing\.js\r?\n/)
.to.match(/ok 4 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: resolver\.js\r?\n/)
.to.match(/ok 5 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: router\.js\r?\n/)
.to.match(/not ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: unused\.js\r?\n/);
expect(result.stdout)
.to.match(/ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/destroy-app\.js\r?\n/)
.to.match(/ok 8 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/module-for-acceptance\.js\r?\n/)
.to.match(/ok 9 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/start-app\.js\r?\n/)
.to.match(/ok 10 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: test-helper\.js\r?\n/);
})
});
it('passes if jsx files are included', function() {
process.env['JSX'] = true;
return emberTest().then(function(result) {
expect(result.error).to.not.exist;
expect(result.stdout)
.to.match(/ok 1 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: app\.js\r?\n/)
.to.match(/ok 2 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: controllers\/thing\.js\r?\n/)
.to.match(/ok 3 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: models\/thing\.js\r?\n/)
.to.match(/ok 4 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: resolver\.js\r?\n/)
.to.match(/ok 5 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: router\.js\r?\n/)
.to.match(/ok 6 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: routes\/thing\.jsx\r?\n/)
.to.not.match(/not ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| app: unused\.js\r?\n/);
expect(result.stdout)
.to.match(/ok 7 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/destroy-app\.js\r?\n/)
.to.match(/ok 8 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/module-for-acceptance\.js\r?\n/)
.to.match(/ok 9 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: helpers\/start-app\.js\r?\n/)
.to.match(/ok 10 Chrome [0-9]+\.[0-9]+ - \[[0-9]+ ms\] - ESLint \| tests: test-helper\.js\r?\n/);
})
});
});
function emberTest() {
return new Promise(function(resolve) {
exec('node_modules/.bin/ember test', { cwd: path.join(__dirname, '..'), env: process.env }, function (error, stdout, stderr) {
resolve({
error: error,
stdout: stdout,
stderr: stderr
});
});
});
}