Skip to content

Commit c58a680

Browse files
committed
Redo snapshot generating logic
1 parent 5f90749 commit c58a680

File tree

3 files changed

+78
-3
lines changed

3 files changed

+78
-3
lines changed

generate-test-screenshots.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/bin/bash
2-
docker run --rm --name test-container -v $(pwd):/home/circleci/codesandbox-client -w /home/circleci/codesandbox-client -d -t codesandbox/node-puppeteer yarn start:test && \
3-
sleep 50 && docker exec -it test-container yarn test:integrations && \
4-
docker stop test-container
2+
docker run --rm --name test-container -v $(pwd):/home/circleci/codesandbox-client -w /home/circleci/codesandbox-client -t codesandbox/node-puppeteer node packages/app/integration-tests/tests/generate-sandboxes.js
14.7 KB
Loading
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const puppeteer = require('puppeteer');
2+
const { exec } = require('child_process');
3+
4+
const SANDBOXES = ['svelte'];
5+
6+
const cp = exec('yarn start:test');
7+
cp.stdout.on('data', data => {
8+
console.log(data.toString());
9+
if (data.toString().includes('Compiled with warnings.')) {
10+
console.log('CSB: Starting tests');
11+
runTests();
12+
}
13+
});
14+
15+
async function runTests() {
16+
function pageLoaded(page) {
17+
return new Promise(async resolve => {
18+
await page.exposeFunction('__puppeteer__', () => {
19+
if (resolve) {
20+
resolve();
21+
}
22+
});
23+
});
24+
}
25+
26+
let browser = puppeteer.launch({
27+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
28+
});
29+
30+
await Promise.all(
31+
SANDBOXES.map(async sandbox => {
32+
const id = sandbox.id || sandbox;
33+
34+
console.log('Loading browser');
35+
browser = await browser;
36+
const page = await browser.newPage();
37+
console.log('Opened new page');
38+
const waitFunction = pageLoaded(page);
39+
console.log('Page loaded');
40+
41+
page.on('console', msg =>
42+
msg.args().forEach(async arg => {
43+
console.log(await arg.jsonValue());
44+
})
45+
);
46+
page.on('requestfailed', err => console.log(err));
47+
48+
console.log('Going to', 'http://localhost:3002/#' + id);
49+
await page.goto('http://localhost:3002/#' + id, {
50+
timeout: 60000,
51+
});
52+
console.log('Went to ' + id);
53+
54+
await waitFunction;
55+
console.log('Waited');
56+
await page.waitFor(sandbox.waitFor || 2000);
57+
console.log('Another wait');
58+
59+
const screenshot = await page.screenshot();
60+
61+
require('fs').writeFileSync(
62+
require('path').join(
63+
__dirname,
64+
`__image_snapshots__`,
65+
`${id.split('/').join('-')}-snap.png`
66+
),
67+
screenshot
68+
);
69+
70+
console.log('Saved screenshot');
71+
72+
await page.close();
73+
})
74+
);
75+
76+
process.kill(0);
77+
}

0 commit comments

Comments
 (0)