Skip to content

Commit

Permalink
infra(e2e-test-kit): default project runner inner step timeout flakin…
Browse files Browse the repository at this point in the history
…ess (#2655)
  • Loading branch information
idoros authored Aug 9, 2022
1 parent 8bd18a3 commit 5609827
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
19 changes: 15 additions & 4 deletions packages/e2e-test-kit/src/project-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from 'util';
import webpack from 'webpack';
import { nodeFs } from '@file-services/node';
import { symlinkSync, existsSync, realpathSync } from 'fs';
import { deferred } from 'promise-assist';
import { deferred, waitFor, timeout } from 'promise-assist';
import { runServer } from './run-server';
import { createTempDirectorySync } from './file-system-helpers';
import { loadDirSync } from './file-system-helpers';
Expand All @@ -22,6 +22,7 @@ export interface Options {
watchMode?: boolean;
useTempDir?: boolean;
tempDirPath?: string;
totalTestTime?: number;
}

type MochaHook = import('mocha').HookFunction;
Expand All @@ -38,7 +39,7 @@ export class ProjectRunner {
const projectRunner = new this(runnerOptions);

before('bundle and serve project', async function () {
this.timeout(40000);
this.timeout(runnerOptions.totalTestTime ?? 40000);
await projectRunner.run();
await projectRunner.serve();
});
Expand Down Expand Up @@ -136,13 +137,23 @@ export class ProjectRunner {
public async actAndWaitForRecompile(
actionDesc: string,
action: () => Promise<void> | void,
validate: () => Promise<void> | void = () => Promise.resolve()
validate: (controlledWaitFor: typeof waitFor) => Promise<void> | void = () =>
Promise.resolve()
) {
const timeoutMs = 15000;
const controlledWaitFor: typeof waitFor = (action, options = {}) => {
// ToDo: figure out how to add time to the total test timeout
return waitFor(action, { timeout: timeoutMs, ...options });
};
try {
const recompile = this.waitForRecompile();
await action();
await recompile;
await validate();
await timeout(
validate(controlledWaitFor) || Promise.resolve(),
timeoutMs + 100, // allow inner timeout to fail first
`[timeout after ${timeoutMs + 100}ms] "${actionDesc}"`
);
} catch (e) {
if (e) {
(e as Error).message = actionDesc + '\n' + (e as Error).message;
Expand Down
3 changes: 1 addition & 2 deletions packages/webpack-plugin/test/e2e/deep-js.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { StylableProjectRunner } from '@stylable/e2e-test-kit';
import { expect } from 'chai';
import { promises } from 'fs';
import { dirname, join } from 'path';
import { waitFor } from 'promise-assist';

const project = 'deep-js';
const projectDir = dirname(
Expand Down Expand Up @@ -37,7 +36,7 @@ describe(`(${project})`, () => {
join(projectRunner.testDir, 'src', 'mixin.js'),
`module.exports = () => ({ color: 'green' });`
),
() =>
(waitFor) =>
waitFor(
async () => {
await page.reload();
Expand Down
9 changes: 4 additions & 5 deletions packages/webpack-plugin/test/e2e/stc-watched-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { promises } from 'fs';
import { dirname, join } from 'path';
import { expect } from 'chai';
import { browserFunctions, StylableProjectRunner } from '@stylable/e2e-test-kit';
import { waitFor } from 'promise-assist';

const { writeFile } = promises;

Expand Down Expand Up @@ -46,7 +45,7 @@ describe(`(${project})`, () => {
join(projectRunner.testDir, 'style-source', 'style-b.st.css'),
'.b{ color: green; }'
),
() =>
(waitFor) =>
waitFor(() => {
expect(projectRunner.getProjectFiles()['style-output/style-b.st.css']).to.eql(
'.b{ color: green; }'
Expand All @@ -68,7 +67,7 @@ describe(`(${project})`, () => {
}
`
),
() =>
(waitFor) =>
waitFor(async () => {
await page.reload();
const styleElements = await page.evaluate(
Expand All @@ -90,7 +89,7 @@ describe(`(${project})`, () => {
join(projectRunner.testDir, 'style-source', 'style-b.st.css'),
'.b{ color: blue; }'
),
() =>
(waitFor) =>
waitFor(
async () => {
expect(
Expand All @@ -108,7 +107,7 @@ describe(`(${project})`, () => {
/\.index\d+__root \{ color: blue; z-index: 1; \}/
);
},
{ timeout: 5_000, delay: 0 }
{ delay: 0 }
)
);
});
Expand Down

0 comments on commit 5609827

Please sign in to comment.