Skip to content

Commit ae8d4b2

Browse files
authored
fix: cleanup test flake (#21989)
* fix: test flake in e2e tests * fix flake in GitDataSource.spec.ts
1 parent 566a7b1 commit ae8d4b2

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

packages/data-context/test/unit/sources/GitDataSource.spec.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ describe('GitDataSource', () => {
4747
const onGitInfoChange = sinon.stub()
4848
const onError = sinon.stub()
4949

50+
// create a file and modify a file to express all
51+
// git states we are interested in (created, unmodified, modified)
52+
const fooSpec = path.join(e2eFolder, 'foo.cy.js')
53+
const aRecordSpec = path.join(e2eFolder, 'a_record.cy.js')
54+
const xhrSpec = path.join(e2eFolder, 'xhr.cy.js')
55+
5056
gitInfo = new GitDataSource({
5157
isRunMode: false,
5258
projectRoot: projectPath,
@@ -55,28 +61,24 @@ describe('GitDataSource', () => {
5561
onError,
5662
})
5763

58-
// create a file and modify a file to express all
59-
// git states we are interested in (created, unmodified, modified)
60-
const fooSpec = path.join(e2eFolder, 'foo.cy.js')
61-
const aRecordSpec = path.join(e2eFolder, 'a_record.cy.js')
62-
const xhrSpec = path.join(e2eFolder, 'xhr.cy.js')
63-
6464
fs.createFileSync(fooSpec)
6565
fs.writeFileSync(xhrSpec, 'it(\'modifies the file\', () => {})')
6666

67-
const dfd = pDefer()
67+
gitInfo.setSpecs([fooSpec, aRecordSpec, xhrSpec])
6868

69-
onGitInfoChange.onSecondCall().callsFake(dfd.resolve)
69+
let result: any[] = []
7070

71-
gitInfo.setSpecs([fooSpec, aRecordSpec, xhrSpec])
71+
do {
72+
result = await Promise.all([
73+
gitInfo.gitInfoFor(fooSpec),
74+
gitInfo.gitInfoFor(aRecordSpec),
75+
gitInfo.gitInfoFor(xhrSpec),
76+
])
7277

73-
await dfd.promise
78+
await new Promise((resolve) => setTimeout(resolve, 100))
79+
} while (result.some((r) => r == null))
7480

75-
const [created, unmodified, modified] = await Promise.all([
76-
gitInfo.gitInfoFor(fooSpec),
77-
gitInfo.gitInfoFor(aRecordSpec),
78-
gitInfo.gitInfoFor(xhrSpec),
79-
])
81+
const [created, unmodified, modified] = result
8082

8183
expect(created.lastModifiedHumanReadable).to.match(/(a few|[0-9]) seconds? ago/)
8284
expect(created.statusType).to.eql('created')

system-tests/projects/missing-webpack-config/cypress.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { defineConfig } from 'cypress'
1+
const { defineConfig } = require('cypress')
22

3-
export default defineConfig({
3+
module.exports = defineConfig({
44
component: {
55
supportFile: false,
66
devServer: {

system-tests/projects/missing-webpack-config/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"webpack": "^5.0.0",
77
"webpack-dev-server": "4.9.0"
88
}
9-
}
9+
}

0 commit comments

Comments
 (0)