Skip to content

test(e2e): Set up fake registry for E2E tests #5806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d3f1674
test(e2e): Set up test registry for E2E tests
lforst Sep 22, 2022
f9a0577
Use local npmrc to publish to test registry
lforst Sep 22, 2022
4e1d6d1
Convert to TS script
lforst Sep 23, 2022
4bb7418
Yarn install in workflow
lforst Sep 23, 2022
d206f82
Remove cwd to fix CI?
lforst Sep 23, 2022
4996956
Remove node env to fix CI?
lforst Sep 23, 2022
923be27
Pass current env to fix CI?
lforst Sep 23, 2022
a904675
Add registry flag to fix CI???
lforst Sep 23, 2022
c1537e1
Omg just work
lforst Sep 23, 2022
55e6561
Omg just work
lforst Sep 23, 2022
7c43399
Finally
lforst Sep 23, 2022
7cdc527
Add individual packages to verdaccio config
lforst Sep 26, 2022
fc14bbb
Clean up dependencies?
lforst Sep 26, 2022
5c9e8ed
Move e2e tests into workspace
lforst Sep 26, 2022
ea0155f
Rename verdaccio config folder
lforst Sep 26, 2022
c16a103
Extract verdaccio version into const
lforst Sep 26, 2022
519f598
Rename ci step
lforst Sep 26, 2022
0709dd6
Add license
lforst Sep 26, 2022
8eb8cc7
Remove node types
lforst Sep 26, 2022
ea33b5f
Turn off npm audit in verdaccio config
lforst Sep 26, 2022
25335fb
Add lint command
lforst Sep 26, 2022
432c850
Add yaml package and pin deps
lforst Sep 26, 2022
1904a06
Add quick validation script
lforst Sep 26, 2022
a7c5664
Containerize the process of publishing packages to fake registry
lforst Sep 26, 2022
8c3e5e6
Update eslintrc
lforst Sep 26, 2022
d648a03
Improve log message in validation script
lforst Sep 26, 2022
c5e4c20
Remove -it flag from docker run
lforst Sep 26, 2022
dfe6809
Remove --sig-proxy flag
lforst Sep 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,35 @@ jobs:
run: |
cd packages/remix
yarn test:integration:ci

job_e2e_tests:
name: E2E Tests
needs: [job_get_metadata, job_build]
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true
steps:
- name: Check out current commit (${{ needs.job_get_metadata.outputs.commit_label }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: ${{ env.DEFAULT_NODE_VERSION }}
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Run E2E tests
env:
E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION: ${{ env.DEFAULT_NODE_VERSION }}
run: |
cd packages/e2e-tests
yarn test:e2e
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"packages/angular",
"packages/browser",
"packages/core",
"packages/e2e-tests",
"packages/ember",
"packages/eslint-config-sdk",
"packages/eslint-plugin-sdk",
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-tests/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
env: {
node: true,
},
extends: ['../../.eslintrc.js'],
ignorePatterns: [],
parserOptions: {
sourceType: 'module',
},
};
6 changes: 6 additions & 0 deletions packages/e2e-tests/Dockerfile.publish-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This Dockerfile exists for the purpose of using a specific node/npm version (ie. the same we use in CI) to run npm publish with
ARG NODE_VERSION=16.15.1
FROM node:${NODE_VERSION}

WORKDIR /sentry-javascript/packages/e2e-tests
CMD [ "yarn", "ts-node", "publish-packages.ts" ]
29 changes: 29 additions & 0 deletions packages/e2e-tests/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
MIT License

Copyright (c) 2022, Sentry
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 changes: 27 additions & 0 deletions packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@sentry-internal/e2e-tests",
"version": "7.13.0",
"license": "MIT",
"engines": {
"node": ">=10"
},
"private": true,
"scripts": {
"fix": "run-s fix:eslint fix:prettier",
"fix:eslint": "eslint . --format stylish --fix",
"fix:prettier": "prettier --config ../../.prettierrc.json --write . ",
"lint": "run-s lint:prettier lint:eslint",
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
"lint:prettier": "prettier --config ../../.prettierrc.json --check .",
"test:e2e": "run-s test:validate-configuration test:run",
"test:run": "ts-node run.ts",
"test:validate-configuration": "ts-node validate-verdaccio-configuration.ts"
},
"devDependencies": {
"@types/glob": "8.0.0",
"glob": "8.0.3",
"ts-node": "10.9.1",
"typescript": "3.8.3",
"yaml": "2.1.1"
}
}
25 changes: 25 additions & 0 deletions packages/e2e-tests/publish-packages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* eslint-disable no-console */
import * as childProcess from 'child_process';
import * as glob from 'glob';
import * as path from 'path';

const repositoryRoot = path.resolve(__dirname, '../..');

// Create tarballs
childProcess.execSync('yarn build:npm', { encoding: 'utf8', cwd: repositoryRoot, stdio: 'inherit' });

// Get absolute paths of all the packages we want to publish to the fake registry
const packageTarballPaths = glob.sync('packages/*/sentry-*.tgz', {
cwd: repositoryRoot,
absolute: true,
});

// Publish built packages to the fake registry
packageTarballPaths.forEach(tarballPath => {
// `--userconfig` flag needs to be before `publish`
childProcess.execSync(`npm --userconfig ${__dirname}/test-registry.npmrc publish ${tarballPath}`, {

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [file name](1).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to just use craft here (https://github.com/getsentry/craft/blob/master/src/targets/npm.ts#L160), but doesn't support custom user configs so we can stick with this.

cwd: repositoryRoot, // Can't use __dirname here because npm would try to publish `@sentry-internal/e2e-tests`
encoding: 'utf8',
stdio: 'inherit',
});
});
52 changes: 52 additions & 0 deletions packages/e2e-tests/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint-disable no-console */
import * as childProcess from 'child_process';
import * as path from 'path';

const repositoryRoot = path.resolve(__dirname, '../..');

const TEST_REGISTRY_CONTAINER_NAME = 'verdaccio-e2e-test-registry';
const VERDACCIO_VERSION = '5.15.3';

const PUBLISH_PACKAGES_DOCKER_IMAGE_NAME = 'publish-packages';

const publishScriptNodeVersion = process.env.E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION;

try {
// Stop test registry container (Verdaccio) if it was already running
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { stdio: 'ignore' });
console.log('Stopped previously running test registry');
} catch (e) {
// Don't throw if container wasn't running
}

// Start test registry (Verdaccio)
childProcess.execSync(
`docker run --detach --rm --name ${TEST_REGISTRY_CONTAINER_NAME} -p 4873:4873 -v ${__dirname}/verdaccio-config:/verdaccio/conf verdaccio/verdaccio:${VERDACCIO_VERSION}`,
{ encoding: 'utf8', stdio: 'inherit' },
);

// Build container image that is uploading our packages to fake registry with specific Node.js/npm version
childProcess.execSync(
`docker build --tag ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME} --file ./Dockerfile.publish-packages ${
publishScriptNodeVersion ? `--build-arg NODE_VERSION=${publishScriptNodeVersion}` : ''
} .`,
{
encoding: 'utf8',
stdio: 'inherit',
},
);

// Run container that uploads our packages to fake registry
childProcess.execSync(
`docker run --rm -v ${repositoryRoot}:/sentry-javascript --network host ${PUBLISH_PACKAGES_DOCKER_IMAGE_NAME}`,

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [absolute path](1).
{
encoding: 'utf8',
stdio: 'inherit',
},
);

// TODO: Run e2e tests here

// Stop test registry
childProcess.execSync(`docker stop ${TEST_REGISTRY_CONTAINER_NAME}`, { encoding: 'utf8', stdio: 'ignore' });
console.log('Successfully stopped test registry container'); // Output from command above is not good so we `ignore` it and emit our own
3 changes: 3 additions & 0 deletions packages/e2e-tests/test-registry.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@sentry:registry=http://localhost:4873
@sentry-internal:registry=http://localhost:4873
//localhost:4873/:_authToken=some-token
6 changes: 6 additions & 0 deletions packages/e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["node"]
}
}
45 changes: 45 additions & 0 deletions packages/e2e-tests/validate-verdaccio-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as assert from 'assert';
import * as fs from 'fs';
import * as glob from 'glob';
import * as path from 'path';
import * as YAML from 'yaml';

/*
* This file is a quick automatic check to confirm that the packages in the Verdaccio configuration always match the
* packages we defined in our monorepo. This is to ensure that the E2E tests do not use the packages that live on NPM
* but the local ones instead.
*/

const repositoryRoot = path.resolve(__dirname, '../..');

const verdaccioConfigContent = fs.readFileSync('./verdaccio-config/config.yaml', { encoding: 'utf8' });
const verdaccioConfig = YAML.parse(verdaccioConfigContent);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const sentryScopedPackagesInVerdaccioConfig = Object.keys(verdaccioConfig.packages).filter(packageName =>
packageName.startsWith('@sentry/'),
);

const packageJsonPaths = glob.sync('packages/*/package.json', {
cwd: repositoryRoot,
absolute: true,
});
const packageJsons = packageJsonPaths.map(packageJsonPath => require(packageJsonPath));
const sentryScopedPackageNames = packageJsons
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.filter(packageJson => packageJson.name.startsWith('@sentry/'))
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
.map(packageJson => packageJson.name);

const extraPackagesInVerdaccioConfig = sentryScopedPackagesInVerdaccioConfig.filter(
x => !sentryScopedPackageNames.includes(x),
);
const extraPackagesInMonoRepo = sentryScopedPackageNames.filter(
x => !sentryScopedPackagesInVerdaccioConfig.includes(x),
);

assert.ok(
extraPackagesInVerdaccioConfig.length === 0 && extraPackagesInMonoRepo.length === 0,
`Packages in Verdaccio configuration do not match the "@sentry"-scoped packages in monorepo. Make sure they match!\nPackages missing in Verdaccio configuration: ${JSON.stringify(
extraPackagesInMonoRepo,
)}\nPackages missing in monorepo: ${JSON.stringify(extraPackagesInVerdaccioConfig)}`,
);
Loading