Skip to content

Commit 30e978b

Browse files
author
Luca Forstner
committed
test(e2e): Add E2E Test recipe framework
1 parent 12c19d0 commit 30e978b

File tree

1 file changed

+54
-37
lines changed

1 file changed

+54
-37
lines changed

packages/e2e-tests/run.ts

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,59 @@ const PUBLISH_PACKAGES_DOCKER_IMAGE_NAME = 'publish-packages';
1111

1212
const publishScriptNodeVersion = process.env.E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION;
1313

14-
try {
15-
// Stop test registry container (Verdaccio) if it was already running
16-
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { stdio: 'ignore' });
17-
console.log('Stopped previously running test registry');
18-
} catch (e) {
19-
// Don't throw if container wasn't running
14+
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
15+
function groupCIOutput(groupTitle: string, fn: () => void): void {
16+
if (process.env.CI) {
17+
console.log(`::group::{${groupTitle}}`);
18+
fn();
19+
console.log('::endgroup::');
20+
} else {
21+
fn();
22+
}
2023
}
2124

22-
// Start test registry (Verdaccio)
23-
childProcess.execSync(
24-
`docker run --detach --rm --name ${TEST_REGISTRY_CONTAINER_NAME} -p 4873:4873 -v ${__dirname}/verdaccio-config:/verdaccio/conf verdaccio/verdaccio:${VERDACCIO_VERSION}`,
25-
{ encoding: 'utf8', stdio: 'inherit' },
26-
);
27-
28-
// Build container image that is uploading our packages to fake registry with specific Node.js/npm version
29-
childProcess.execSync(
30-
`docker build --tag ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME} --file ./Dockerfile.publish-packages ${
31-
publishScriptNodeVersion ? `--build-arg NODE_VERSION=${publishScriptNodeVersion}` : ''
32-
} .`,
33-
{
34-
encoding: 'utf8',
35-
stdio: 'inherit',
36-
},
37-
);
38-
39-
// Run container that uploads our packages to fake registry
40-
childProcess.execSync(
41-
`docker run --rm -v ${repositoryRoot}:/sentry-javascript --network host ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME}`,
42-
{
43-
encoding: 'utf8',
44-
stdio: 'inherit',
45-
},
46-
);
47-
48-
// TODO: Run e2e tests here
49-
50-
// Stop test registry
51-
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { encoding: 'utf8', stdio: 'ignore' });
52-
console.log('Successfully stopped test registry container'); // Output from command above is not good so we `ignore` it and emit our own
25+
groupCIOutput('Test Registry Setup', () => {
26+
try {
27+
// Stop test registry container (Verdaccio) if it was already running
28+
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { stdio: 'ignore' });
29+
console.log('Stopped previously running test registry');
30+
} catch (e) {
31+
// Don't throw if container wasn't running
32+
}
33+
34+
// Start test registry (Verdaccio)
35+
childProcess.execSync(
36+
`docker run --detach --rm --name ${TEST_REGISTRY_CONTAINER_NAME} -p 4873:4873 -v ${__dirname}/verdaccio-config:/verdaccio/conf verdaccio/verdaccio:${VERDACCIO_VERSION}`,
37+
{ encoding: 'utf8', stdio: 'inherit' },
38+
);
39+
40+
// Build container image that is uploading our packages to fake registry with specific Node.js/npm version
41+
childProcess.execSync(
42+
`docker build --tag ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME} --file ./Dockerfile.publish-packages ${
43+
publishScriptNodeVersion ? `--build-arg NODE_VERSION=${publishScriptNodeVersion}` : ''
44+
} .`,
45+
{
46+
encoding: 'utf8',
47+
stdio: 'inherit',
48+
},
49+
);
50+
51+
// Run container that uploads our packages to fake registry
52+
childProcess.execSync(
53+
`docker run --rm -v ${repositoryRoot}:/sentry-javascript --network host ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME}`,
54+
{
55+
encoding: 'utf8',
56+
stdio: 'inherit',
57+
},
58+
);
59+
});
60+
61+
groupCIOutput('Run E2E Test Suites', () => {
62+
// TODO: Run e2e tests here
63+
});
64+
65+
groupCIOutput('Cleanup', () => {
66+
// Stop test registry
67+
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { encoding: 'utf8', stdio: 'ignore' });
68+
console.log('Successfully stopped test registry container'); // Output from command above is not good so we `ignore` it and emit our own
69+
});

0 commit comments

Comments
 (0)