Skip to content

Commit

Permalink
try building test image
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-kerem committed Apr 17, 2024
1 parent ca59de6 commit 7ba71f7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/jest.config.cjs
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,
};
42 changes: 42 additions & 0 deletions tests/utils/helpers.ts
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);
});
}
12 changes: 12 additions & 0 deletions tests/utils/runner.ts
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;

0 comments on commit 7ba71f7

Please sign in to comment.