-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
testMatch: ['**/tests/*.spec.ts'], | ||
testPathIgnorePatterns: ['/project/', '/node_modules/'], | ||
runner: './utils/runner.ts', | ||
setupFilesAfterEnv: ['jest-extended/all'], | ||
bail: 1, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Build, BuildStatus, VisualApi } from "@saucelabs/visual"; | ||
|
||
export const RE_VISUAL_BUILD_ID = | ||
/([a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12})/; | ||
|
||
export const waitStatusForBuild = async function ( | ||
api: VisualApi, | ||
buildId: string, | ||
status: BuildStatus[], | ||
options?: { | ||
refreshRate?: number; | ||
retries?: number; | ||
buildIdType?: 'customId' | 'buildId'; | ||
}, | ||
): Promise<Partial<Build> | undefined> { | ||
const { | ||
refreshRate = 500, | ||
buildIdType = 'buildId', | ||
retries = 10, | ||
} = options ?? {}; | ||
let currentTry = 0; | ||
do { | ||
currentTry++; | ||
const build = | ||
buildIdType === 'buildId' | ||
? await api.build(buildId) | ||
: await api.buildByCustomId(buildId); | ||
if (build?.status && status.includes(build?.status)) { | ||
return build; | ||
} | ||
await wait(refreshRate); | ||
} while (currentTry < retries); | ||
throw new Error( | ||
`Expected status ${status} never received for build ${buildId}`, | ||
); | ||
}; | ||
|
||
async function wait(delayMs: number): Promise<void> { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, delayMs); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import DefaultJestRunner, { Config, TestRunnerContext } from 'jest-runner'; | ||
|
||
class SerialJestRunner extends DefaultJestRunner { | ||
declare isSerial?: boolean; | ||
|
||
constructor(_globalConfig: Config.GlobalConfig, _context: TestRunnerContext) { | ||
super(_globalConfig, _context); | ||
this.isSerial = true; | ||
} | ||
} | ||
|
||
module.exports = SerialJestRunner; |