Skip to content

Commit 71ebdac

Browse files
committed
fix(): fix timeout for screenshot
1 parent cc293ea commit 71ebdac

File tree

10 files changed

+35
-36
lines changed

10 files changed

+35
-36
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ jobs:
5151
steps:
5252
- attach_workspace:
5353
at: ~/stencil
54-
- run: npm run test.end-to-end -- --ci --debug --max-workers=4
54+
- run: npm run test.end-to-end -- --ci
5555

5656
test_jest:
5757
<<: *defaults
5858
steps:
5959
- attach_workspace:
6060
at: ~/stencil
61-
- run: npm run test.jest -- --max-workers=4
61+
- run: npm run test.jest -- --maxWorkers=1
6262

6363
test_sys_node:
6464
<<: *defaults

src/runtime/test/globals.spec.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ describe('globals', () => {
4949
html: `<cmp-el></cmp-el>`
5050
});
5151

52-
expect(page.rootInstance.proto).toBe(Element.prototype);
53-
expect(page.rootInstance.proto).toBe((page.win as any).Element.prototype);
54-
expect(page.rootInstance.proto).toBe((window as any).Element.prototype);
55-
expect(page.rootInstance.proto).toBe((global as any).Element.prototype);
52+
expect(page.rootInstance.proto).toEqual(Element.prototype);
53+
expect(page.rootInstance.proto).toEqual((page.win as any).Element.prototype);
54+
expect(page.rootInstance.proto).toEqual((window as any).Element.prototype);
55+
expect(page.rootInstance.proto).toEqual((global as any).Element.prototype);
5656
expect(page.rootInstance.proto).toBeTruthy();
5757
});
5858
});

src/screenshot/connector-base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ScreenshotConnector implements d.ScreenshotConnector {
4747
this.packageDir = opts.packageDir;
4848
this.rootDir = opts.rootDir;
4949
this.appNamespace = opts.appNamespace;
50-
this.timeoutBeforeScreenshot = typeof opts.timeoutBeforeScreenshot === 'number' ? opts.timeoutBeforeScreenshot : 4;
50+
this.timeoutBeforeScreenshot = typeof opts.timeoutBeforeScreenshot === 'number' ? opts.timeoutBeforeScreenshot : 0;
5151
this.pixelmatchModulePath = opts.pixelmatchModulePath;
5252

5353
if (!opts.logger) {

src/testing/jest/jest-config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ export function buildJestArgv(config: d.Config) {
99
...config.flags.knownArgs.slice()
1010
];
1111

12-
if (config.flags.e2e && config.flags.ci && !args.some(a => a.startsWith('--max-workers') || a.startsWith('--maxWorkers'))) {
13-
args.push('--maxWorkers=4');
14-
}
15-
if (config.flags.devtools) {
16-
args.push('--maxWorkers=1');
12+
if (config.flags.e2e && (config.flags.ci || config.flags.devtools)) {
13+
if (!args.some(a => a.startsWith('--max-workers') || a.startsWith('--maxWorkers'))) {
14+
args.push('--max-workers=1');
15+
}
1716
args.push('--runInBand');
1817
}
1918

2019
config.logger.debug(`jest args: ${args.join(' ')}`);
2120

2221
const { options } = require('jest-cli/build/cli/args');
2322
const jestArgv = yargs(args).options(options).argv as d.JestArgv;
24-
2523
jestArgv.config = buildJestConfig(config);
2624

2725
return jestArgv;

src/testing/jest/jest-screenshot.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export async function runJestScreenshot(config: d.Config, env: d.E2EProcessEnv)
99
const connector: d.ScreenshotConnector = new ScreenshotConnector();
1010

1111
// for CI, let's wait a little longer than locally before taking the screenshot
12-
const timeoutBeforeScreenshot = config.flags.ci ? 30 : 10;
13-
12+
const timeoutBeforeScreenshot = 0;
1413
const pixelmatchModulePath = config.sys.path.join(config.sys.compiler.packageDir, 'screenshot', 'pixel-match.js');
1514
config.logger.debug(`pixelmatch module: ${pixelmatchModulePath}`);
1615

src/testing/jest/test/jest-config.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ describe('jest-config', () => {
2525

2626
it('pass --maxWorkers=2 arg when e2e test and --ci', () => {
2727
const process: any = {
28-
argv: ['node', 'stencil', 'test', '--ci', '--e2e', '--maxWorkers=2']
28+
argv: ['node', 'stencil', 'test', '--ci', '--e2e', '--max-workers=2']
2929
};
3030
const config = mockConfig();
3131
config.flags = parseFlags(process);
3232
config.testing = {};
3333

34-
expect(config.flags.args).toEqual(['--ci', '--e2e', '--maxWorkers=2']);
34+
expect(config.flags.args).toEqual(['--ci', '--e2e', '--max-workers=2']);
3535
expect(config.flags.unknownArgs).toEqual([]);
3636

3737
const jestArgv = buildJestArgv(config);
@@ -52,7 +52,7 @@ describe('jest-config', () => {
5252

5353
const jestArgv = buildJestArgv(config);
5454
expect(jestArgv.ci).toBe(true);
55-
expect(jestArgv.maxWorkers).toBe(4);
55+
expect(jestArgv.maxWorkers).toBe(1);
5656
});
5757

5858
it('pass --maxWorkers=2 arg to jest', () => {

src/testing/puppeteer/puppeteer-screenshot.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,20 @@ export async function pageCompareScreenshot(page: pd.E2EPageInternal, env: d.E2E
8484
const emulateConfig = JSON.parse(env.__STENCIL_EMULATE__) as d.EmulateConfig;
8585
const screenshotBuildData = JSON.parse(env.__STENCIL_SCREENSHOT_BUILD__) as d.ScreenshotBuildData;
8686

87-
await (page as any).waitForNavigation({
88-
timeout: screenshotBuildData.timeoutBeforeScreenshot,
89-
waitUntil: 'networkidle0'
90-
});
91-
87+
await wait(screenshotBuildData.timeoutBeforeScreenshot);
9288
await page.evaluate(() => {
9389
return new Promise(resolve => {
94-
window.requestAnimationFrame(() => {
95-
resolve();
96-
});
90+
(window as any).requestIdleCallback(() => {
91+
window.requestAnimationFrame(() => {
92+
resolve();
93+
});
94+
}, { timeout: 100 });
9795
});
9896
});
9997

10098
const screenshotOpts = createPuppeteerScreenshopOptions(opts);
10199
const screenshotBuf = await page.screenshot(screenshotOpts);
102-
103100
const pixelmatchThreshold = (typeof opts.pixelmatchThreshold === 'number' ? opts.pixelmatchThreshold : screenshotBuildData.pixelmatchThreshold);
104-
105101
const results = await compareScreenshot(emulateConfig, screenshotBuildData, screenshotBuf, desc, testPath, pixelmatchThreshold);
106102

107103
return results;
@@ -127,3 +123,7 @@ function createPuppeteerScreenshopOptions(opts: d.ScreenshotOptions) {
127123

128124
return puppeteerOpts;
129125
}
126+
127+
function wait(ms: number) {
128+
return new Promise<void>(resolve => setTimeout(resolve, ms));
129+
}

test/karma/karma.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var browserStackLaunchers = {
3030
base: 'BrowserStack',
3131
browser: 'safari',
3232
os: 'OS X',
33-
os_version: 'High Sierra'
33+
os_version: 'Mojave'
3434
}
3535
};
3636

test/karma/test-app/attribute-complex/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
<attribute-complex></attribute-complex>
77

88
<script>
9-
customElements.whenDefined('attribute-complex').then(function() {
10-
var el = document.querySelector('attribute-complex');
11-
el.getInstance();
12-
});
9+
if (window.customElements) {
10+
customElements.whenDefined('attribute-complex').then(function() {
11+
var el = document.querySelector('attribute-complex');
12+
el.getInstance();
13+
});
14+
}
1315
</script>

test/karma/test-app/esm-import/karma.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if (typeof (window as any).CustomEvent !== 'function') {
6565
}
6666

6767
function buttonClick(button: HTMLButtonElement) {
68-
// const event = new (window as any).CustomEvent('click', { 'bubbles': true, composed: true } as any);
69-
// button.dispatchEvent(event);
70-
button.click();
68+
const event = new (window as any).CustomEvent('click', { 'bubbles': true, composed: true } as any);
69+
button.dispatchEvent(event);
70+
// button.click();
7171
}

0 commit comments

Comments
 (0)