-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from all commits
d3f1674
f9a0577
4e1d6d1
4bb7418
d206f82
4996956
923be27
a904675
c1537e1
55e6561
7c43399
7cdc527
fc14bbb
5c9e8ed
ea0155f
c16a103
519f598
0709dd6
8eb8cc7
ea33b5f
25335fb
432c850
1904a06
a7c5664
8c3e5e6
d648a03
c5e4c20
dfe6809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
}, | ||
}; |
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" ] |
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. |
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" | ||
} | ||
} |
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 warningCode scanning / CodeQL Shell command built from environment values
This shell command depends on an uncontrolled [file name](1).
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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', | ||
}); | ||
}); |
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 warningCode 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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["node"] | ||
} | ||
} |
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)}`, | ||
); |
Uh oh!
There was an error while loading. Please reload this page.