Skip to content

Commit c9da46b

Browse files
committed
feat: add retry logic
1 parent 1755930 commit c9da46b

6 files changed

Lines changed: 389 additions & 42 deletions

File tree

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
lib
22
jest.config.js
3-
jest-puppeteer.config.js

packages/web-functionality/jest-puppeteer.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
module.exports = {
22
preset: 'jest-puppeteer',
3-
haste: {
4-
providesModuleNodeModules: ['.*'],
5-
},
3+
testResultsProcessor: 'jest-junit',
64
testMatch: ['<rootDir>/lib/**/*.test.js'],
5+
6+
/**
7+
* Note the following config is required to support running jest as a CLI.
8+
* Jest doesn't support running tests in `node_modules` by default.
9+
* This is a problem as this CLI is installed within node_modules itself.
10+
*
11+
* Issue: https://github.com/facebook/jest/issues/2145
12+
* This is fixed in Jest v.28, we can migrate to that once it is fully available.
13+
* Until then we need to stay on Jest v.25, as support was dropped in versions 26 and 27.
14+
*/
715
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
816
modulePathIgnorePatterns: ['<rootDir>/node_modules/'],
9-
testResultsProcessor: 'jest-junit',
17+
haste: {
18+
providesModuleNodeModules: ['.*'],
19+
},
1020
}

packages/web-functionality/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"description": "Functionality monitoring for Sourcegraph applications",
44
"license": "Apache-2.0",
55
"version": "0.0.1",
6-
"main": "./lib/src/index.js",
76
"bin": {
87
"start": "./lib/src/index.js"
98
},
@@ -18,7 +17,6 @@
1817
"@sourcegraph/tsconfig": "^4.0.1",
1918
"execa": "^5.1.1",
2019
"jest": "25.5.4",
21-
"jest-cli": "25.5.4",
2220
"jest-junit": "^13.0.0",
2321
"jest-puppeteer": "^6.1.0",
2422
"puppeteer": "^13.0.1"

packages/web-functionality/src/index.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
#!/usr/bin/env node
2-
import execa from 'execa'
2+
import execa, { ExecaReturnValue } from 'execa'
33

44
const { SOURCEGRAPH_URL, JEST_JUNIT_OUTPUT_NAME, JEST_JUNIT_OUTPUT_DIR } = process.env
55

66
if (!SOURCEGRAPH_URL) {
77
throw new Error('SOURCEGRAPH_URL was not set. Please provide a valid URL to run the smoke tests against.')
88
}
99

10+
const runTests = async (): Promise<ExecaReturnValue> =>
11+
/**
12+
* Note: There is no officially supported way to run Jest programmatically.
13+
* We avoid using the unstable `jest.run()` API.
14+
* https://github.com/facebook/jest/issues/5048
15+
*/
16+
execa('jest', ['--runInBand'], {
17+
cwd: __dirname,
18+
shell: true,
19+
stdio: 'inherit',
20+
env: { SOURCEGRAPH_URL, JEST_JUNIT_OUTPUT_NAME, JEST_JUNIT_OUTPUT_DIR },
21+
})
22+
1023
const handler = async (): Promise<void> => {
11-
try {
12-
/**
13-
* Note: There is no officially supported way to run Jest programmatically.
14-
* We avoid using the unstable `jest.run()` API.
15-
* https://github.com/facebook/jest/issues/5048
16-
*/
17-
await execa('jest', ['--runInBand'], {
18-
cwd: __dirname,
19-
shell: true,
20-
stdio: 'inherit',
21-
env: { SOURCEGRAPH_URL, JEST_JUNIT_OUTPUT_NAME, JEST_JUNIT_OUTPUT_DIR },
22-
})
23-
} catch (error) {
24-
console.error(error)
25-
process.exit(error?.exitCode || 1)
24+
for (let index = 0; index < 3; index++) {
25+
try {
26+
await runTests()
27+
break
28+
} catch (error) {
29+
console.error(error)
30+
if (index === 2) {
31+
process.exit(error?.exitCode || 1)
32+
}
33+
}
2634
}
2735
}
2836

0 commit comments

Comments
 (0)