Skip to content

Commit

Permalink
feat: add retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
umpox committed Mar 21, 2022
1 parent 1755930 commit c9da46b
Show file tree
Hide file tree
Showing 6 changed files with 389 additions and 42 deletions.
1 change: 0 additions & 1 deletion packages/web-functionality/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib
jest.config.js
jest-puppeteer.config.js
5 changes: 0 additions & 5 deletions packages/web-functionality/jest-puppeteer.config.js

This file was deleted.

18 changes: 14 additions & 4 deletions packages/web-functionality/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
module.exports = {
preset: 'jest-puppeteer',
haste: {
providesModuleNodeModules: ['.*'],
},
testResultsProcessor: 'jest-junit',
testMatch: ['<rootDir>/lib/**/*.test.js'],

/**
* Note the following config is required to support running jest as a CLI.
* Jest doesn't support running tests in `node_modules` by default.
* This is a problem as this CLI is installed within node_modules itself.
*
* Issue: https://github.com/facebook/jest/issues/2145
* This is fixed in Jest v.28, we can migrate to that once it is fully available.
* Until then we need to stay on Jest v.25, as support was dropped in versions 26 and 27.
*/
testPathIgnorePatterns: ['<rootDir>/node_modules/'],
modulePathIgnorePatterns: ['<rootDir>/node_modules/'],
testResultsProcessor: 'jest-junit',
haste: {
providesModuleNodeModules: ['.*'],
},
}
2 changes: 0 additions & 2 deletions packages/web-functionality/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"description": "Functionality monitoring for Sourcegraph applications",
"license": "Apache-2.0",
"version": "0.0.1",
"main": "./lib/src/index.js",
"bin": {
"start": "./lib/src/index.js"
},
Expand All @@ -18,7 +17,6 @@
"@sourcegraph/tsconfig": "^4.0.1",
"execa": "^5.1.1",
"jest": "25.5.4",
"jest-cli": "25.5.4",
"jest-junit": "^13.0.0",
"jest-puppeteer": "^6.1.0",
"puppeteer": "^13.0.1"
Expand Down
40 changes: 24 additions & 16 deletions packages/web-functionality/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
#!/usr/bin/env node
import execa from 'execa'
import execa, { ExecaReturnValue } from 'execa'

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

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

const runTests = async (): Promise<ExecaReturnValue> =>
/**
* Note: There is no officially supported way to run Jest programmatically.
* We avoid using the unstable `jest.run()` API.
* https://github.com/facebook/jest/issues/5048
*/
execa('jest', ['--runInBand'], {
cwd: __dirname,
shell: true,
stdio: 'inherit',
env: { SOURCEGRAPH_URL, JEST_JUNIT_OUTPUT_NAME, JEST_JUNIT_OUTPUT_DIR },
})

const handler = async (): Promise<void> => {
try {
/**
* Note: There is no officially supported way to run Jest programmatically.
* We avoid using the unstable `jest.run()` API.
* https://github.com/facebook/jest/issues/5048
*/
await execa('jest', ['--runInBand'], {
cwd: __dirname,
shell: true,
stdio: 'inherit',
env: { SOURCEGRAPH_URL, JEST_JUNIT_OUTPUT_NAME, JEST_JUNIT_OUTPUT_DIR },
})
} catch (error) {
console.error(error)
process.exit(error?.exitCode || 1)
for (let index = 0; index < 3; index++) {
try {
await runTests()
break
} catch (error) {
console.error(error)
if (index === 2) {
process.exit(error?.exitCode || 1)
}
}
}
}

Expand Down
Loading

0 comments on commit c9da46b

Please sign in to comment.