-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathalphabetical_order_test.js
More file actions
95 lines (82 loc) · 2.58 KB
/
alphabetical_order_test.js
File metadata and controls
95 lines (82 loc) · 2.58 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
94
95
import { expect } from 'chai'
import Codecept from '../../lib/codecept.js'
import Container from '../../lib/container.js'
import path from 'path'
import fs from 'fs'
import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
describe('Test Files Alphabetical Order', () => {
let codecept
const tempDir = path.join(__dirname, '../data/sandbox/configs/alphabetical_order')
const config = {
tests: `${tempDir}/*_test.js`,
gherkin: { features: null },
output: './output',
hooks: [],
}
before(() => {
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true })
}
fs.writeFileSync(
path.join(tempDir, 'zzz_test.js'),
`
Feature('Test');
Scenario('zzz test', () => {});
`,
)
fs.writeFileSync(
path.join(tempDir, 'aaa_test.js'),
`
Feature('Test');
Scenario('aaa test', () => {});
`,
)
fs.writeFileSync(
path.join(tempDir, 'mmm_test.js'),
`
Feature('Test');
Scenario('mmm test', () => {});
`,
)
})
after(() => {
const files = ['zzz_test.js', 'aaa_test.js', 'mmm_test.js']
files.forEach(file => {
const filePath = path.join(tempDir, file)
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath)
}
})
})
beforeEach(async () => {
codecept = new Codecept(config, {})
await codecept.init(path.join(__dirname, '../data/sandbox'))
})
afterEach(() => {
Container.clear()
})
it('should not sort test files in loadTests (sorting happens in run)', () => {
codecept.loadTests()
if (codecept.testFiles.length === 0) {
console.log('No test files found, skipping test')
return
}
// After loadTests(), files should be in glob order (NOT sorted).
// Sorting should only happen later in run().
const filenames = codecept.testFiles.map(filePath => path.basename(filePath))
// Verify all 3 test files were loaded
expect(filenames).to.include('aaa_test.js')
expect(filenames).to.include('mmm_test.js')
expect(filenames).to.include('zzz_test.js')
expect(filenames.length).to.equal(3)
// Verify that sorting the files produces alphabetical order
const sortedFiles = [...codecept.testFiles].sort()
const sortedFilenames = sortedFiles.map(filePath => path.basename(filePath))
expect(sortedFilenames[0]).to.include('aaa_test.js')
expect(sortedFilenames[1]).to.include('mmm_test.js')
expect(sortedFilenames[2]).to.include('zzz_test.js')
})
})