-
-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathbootstrap_test.js
More file actions
93 lines (87 loc) · 4.22 KB
/
bootstrap_test.js
File metadata and controls
93 lines (87 loc) · 4.22 KB
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
import * as chai from 'chai';
import assert from 'assert';
chai.should();
import path from 'path';
import { exec } from 'child_process';
import debugFactory from 'debug';
const debug = debugFactory('codeceptjs:test');
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const runner = path.join(__dirname, '/../../bin/codecept.js')
const codecept_dir = path.join(__dirname, '/../data/sandbox/configs/bootstrap')
const codecept_run = `${runner} run`
const codecept_run_config = (config, grep) => `${codecept_run} --config ${codecept_dir}/${config} ${grep ? `--grep ${grep}` : ''}`
const config_run_override = (config, override) => `${codecept_run} --config ${codecept_dir}/${config} --override '${JSON.stringify(override)}'`
describe('CodeceptJS Bootstrap and Teardown', () => {
// success
it('should run bootstrap', done => {
exec(codecept_run_config('bootstrap.conf.js', '@important'), (err, stdout) => {
debug(stdout)
stdout.should.include('Filesystem') // feature
stdout.should.include('I am bootstrap')
stdout.should.include('I am teardown')
const lines = stdout.split('\n')
const bootstrapIndex = lines.findIndex(l => l === 'I am bootstrap')
const testIndex = lines.findIndex(l => l.indexOf('Filesystem @main') === 0)
const teardownIndex = lines.findIndex(l => l === 'I am teardown')
assert(testIndex > bootstrapIndex, `${testIndex} (test) > ${bootstrapIndex} (bootstrap)`)
assert(teardownIndex > testIndex, `${teardownIndex} (teardown) > ${testIndex} (test)`)
assert(!err)
done()
})
})
it('should run async bootstrap', done => {
exec(codecept_run_config('bootstrap.async.conf.js', '@important'), (err, stdout) => {
stdout.should.include('Filesystem') // feature
stdout.should.include('I am bootstrap')
stdout.should.include('I am teardown')
const lines = stdout.split('\n')
const bootstrap0Index = lines.indexOf('I am 0 bootstrap')
const teardown0Index = lines.indexOf('I am 0 teardown')
const bootstrapIndex = lines.findIndex(l => l === 'I am bootstrap')
const testIndex = lines.findIndex(l => l.indexOf('Filesystem @main') === 0)
const teardownIndex = lines.findIndex(l => l === 'I am teardown')
assert(bootstrap0Index < bootstrapIndex, `${bootstrap0Index} < ${bootstrapIndex} (bootstrap)`)
assert(teardown0Index < teardownIndex, `${teardown0Index} < ${teardownIndex} (teardown)`)
assert(testIndex > bootstrapIndex, `${testIndex} (test) > ${bootstrapIndex} (bootstrap)`)
assert(teardownIndex > testIndex, `${teardownIndex} (teardown) > ${testIndex} (test)`)
assert(!err)
done()
})
})
// with teaedown - failed tests
it('should fail with code 1 when test failed and async bootstrap/teardown function with args', done => {
exec(config_run_override('bootstrap.async.conf.js', { tests: './failed_test.js' }), (err, stdout) => {
assert(err)
assert.equal(err.code, 1)
stdout.should.include('Filesystem') // feature
stdout.should.include('I am bootstrap')
stdout.should.include('✖ check current dir @slow @important')
stdout.should.include('I am teardown')
done()
})
})
it('should fail with code 1 when test failed and async bootstrap/teardown function without args', done => {
exec(config_run_override('bootstrap.async.conf.js', { tests: './failed_test.js' }), (err, stdout) => {
assert(err)
assert.equal(err.code, 1)
stdout.should.include('Filesystem') // feature
stdout.should.include('I am bootstrap')
stdout.should.include('✖ check current dir @slow @important')
stdout.should.include('I am teardown')
done()
})
})
// with teardown and fail bootstrap - teardown not call
it('should fail with code 1 when async bootstrap failed and not call teardown', done => {
exec(codecept_run_config('without.args.failed.bootstrap.async.func.js'), (err, stdout) => {
assert(err)
assert.equal(err.code, 1)
stdout.should.include('Error from async bootstrap')
stdout.should.not.include('✔ check current dir @slow @important in 2ms')
stdout.should.not.include('I am teardown')
done()
})
})
})