/
testRunWithTags.js
180 lines (159 loc) · 5.39 KB
/
testRunWithTags.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const path = require('path');
const assert = require('assert');
const common = require('../../common.js');
const CommandGlobals = require('../../lib/globals/commands.js');
const MockServer = require('../../lib/mockserver.js');
const {settings} = common;
const {runTests} = common.require('index.js');
describe('testRunWithTags', function() {
before(function(done) {
this.server = MockServer.init();
this.server.on('listening', () => {
done();
});
});
after(function(done) {
CommandGlobals.afterEach.call(this, done);
});
beforeEach(function() {
process.removeAllListeners('exit');
process.removeAllListeners('uncaughtException');
process.removeAllListeners('unhandledRejection');
});
afterEach(function() {
Object.keys(require.cache).filter(i => i.includes('/sampletests')).forEach(function(module) {
delete require.cache[module];
});
});
it('testRunner with tags', function() {
const testsPath = path.join(__dirname, '../../sampletests');
return runTests({
_source: [testsPath],
tag: ['browser']
}, settings({
output: false,
disable_typescript: true,
globals: {
reporter(results) {
assert.strictEqual(Object.keys(results.modules).length, 1);
assert.ok('demoTagTest' in results.modules[`tagswithbrowserobject${path.sep}sample`].completed);
}
}
}));
});
it('testRunWithTags', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests(testsPath, settings({
output: false,
disable_typescript: true,
globals: {
waitForConditionPollInterval: 10,
waitForConditionTimeout: 11,
retryAssertionTimeout: 10,
reporter(results) {
assert.strictEqual(Object.keys(results.modules).length, 3);
assert.ok('demoTagTest' in results.modules[`tags${path.sep}sample`].completed);
assert.ok('otherDemoTagTest' in results.modules[`withsubfolders${path.sep}tags${path.sep}sampleTags`].completed);
assert.ok('demoTest' in results.modules[`withdescribe${path.sep}failures${path.sep}sampleSkipTestcases`].completed);
}
},
tag_filter: ['login']
}));
});
it('testRunWithTagsAndFilterEmpty', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests(testsPath, settings({
globals: {
},
filter: 'syncnames/*',
tag_filter: ['login']
}))
.catch(err => {
assert.ok(err instanceof Error);
assert.ok(err.message.includes('No tests defined!'));
});
});
it('testRunWithTagsAndFilterNotEmpty', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests(testsPath, settings({
globals: {
reporter(results) {
assert.ok('demoTagTest' in results.modules[`tags${path.sep}sample`].completed);
assert.strictEqual(Object.keys(results.modules).length, 1);
}
},
filter: 'tags/*',
tag_filter: ['login']
}));
});
it('testRunWithSkipTagsAndFilterNotEmpty', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests({
_source: [testsPath],
skiptags: ['logout']
}, settings({
globals: {
reporter(results) {
assert.ok('demoTagTest' in results.modules[`tags${path.sep}sample`].completed);
assert.strictEqual(Object.keys(results.modules).length, 1);
}
},
filter: '**/tags/*'
}));
});
it('testRun with filter and skiptags no matches', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests({
_source: [testsPath],
skiptags: ['logout', 'login']
}, settings({
globals: {
reporter(results) {
}
},
filter: '**/tags/*'
})).catch(err => {
return err;
}).then(err => {
assert.ok(err instanceof Error);
assert.ok(err.message.includes('No tests defined! using source folder'), err.message + '\n' + err.stack);
assert.ok(err.detailedErr.includes('- using path filter: **/tags/*'));
assert.ok(err.detailedErr.includes('- using skiptags filter: logout,login'));
});
});
it('testRunWithTagsAndSkipTags', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests({
_source: [testsPath],
skiptags: ['other']
}, settings({
output: false,
disable_typescript: true,
globals: {
reporter(results) {
assert.strictEqual(Object.keys(results.modules).length, 2);
assert.ok('otherDemoTagTest' in results.modules[`withsubfolders${path.sep}tags${path.sep}sampleTags`].completed);
}
},
tag_filter: ['login']
}));
});
it('testRunner with tags and skip tags no matches', function() {
let testsPath = path.join(__dirname, '../../sampletests');
return runTests({
_source: [testsPath],
skiptags: ['login']
}, settings({
globals: {},
output: false,
tag_filter: ['other']
})).catch(err => {
return err;
}).then(err => {
assert.ok(err instanceof Error);
assert.ok(err.message.includes('No tests defined! using source folder'), err.message + '\n' + err.stack);
assert.ok(err.detailedErr.includes('- using tags filter: other'));
assert.ok(err.detailedErr.includes('- using skiptags filter: login'));
});
});
});