-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix/tmp dir build #16859
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
base: develop
Are you sure you want to change the base?
Fix/tmp dir build #16859
Changes from all commits
6efac13
51277ce
5dc6dce
af78dda
0420ec5
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,7 @@ | ||
import { tmpdir } from 'os'; | ||
import { join } from 'path'; | ||
import { rimrafSync } from 'rimraf'; | ||
|
||
const buildDir = join(tmpdir(), 'sentry-e2e-tests-*'); | ||
|
||
process.exit(Number(!rimrafSync([...process.argv.slice(2), buildDir], { glob: true }))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
/* eslint-disable no-console */ | ||
import { spawn } from 'child_process'; | ||
import { type SpawnOptions, spawn } from 'child_process'; | ||
import * as dotenv from 'dotenv'; | ||
import { mkdtemp, rm } from 'fs/promises'; | ||
import { sync as globSync } from 'glob'; | ||
import { tmpdir } from 'os'; | ||
import { join, resolve } from 'path'; | ||
import { basename, join, resolve } from 'path'; | ||
import { rimraf } from 'rimraf'; | ||
import { copyToTemp } from './lib/copyToTemp'; | ||
import { registrySetup } from './registrySetup'; | ||
|
||
const DEFAULT_DSN = 'https://username@domain/123'; | ||
const DEFAULT_SENTRY_ORG_SLUG = 'sentry-javascript-sdks'; | ||
const DEFAULT_SENTRY_PROJECT = 'sentry-javascript-e2e-tests'; | ||
|
||
function asyncExec(command: string, options: { env: Record<string, string | undefined>; cwd: string }): Promise<void> { | ||
function asyncExec(command: string, options: Omit<SpawnOptions, 'shell'|'stdio'>): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
const process = spawn(command, { ...options, shell: true }); | ||
|
||
process.stdout.on('data', data => { | ||
console.log(`${data}`); | ||
}); | ||
|
||
process.stderr.on('data', data => { | ||
console.error(`${data}`); | ||
}); | ||
const process = spawn(command, { ...options, shell: true, stdio: ['ignore', 'inherit', 'inherit'] }); | ||
Comment on lines
+16
to
+18
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. Not necessary, but why not to have it more clean |
||
|
||
process.on('error', error => { | ||
reject(error); | ||
|
@@ -64,21 +57,23 @@ async function run(): Promise<void> { | |
console.log('Cleaning test-applications...'); | ||
console.log(''); | ||
|
||
const tmpPrefix = join(tmpdir(), 'sentry-e2e-tests-') | ||
await rimraf(`${tmpPrefix}*`, { glob: true }); | ||
Comment on lines
+60
to
+61
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. This is here, because |
||
|
||
if (!process.env.SKIP_REGISTRY) { | ||
registrySetup(); | ||
} | ||
|
||
await asyncExec('pnpm clean:test-applications', { env, cwd: __dirname }); | ||
await asyncExec('pnpm cache delete "@sentry/*"', { env, cwd: __dirname }); | ||
|
||
const testAppPaths = appName ? [appName.trim()] : globSync('*', { cwd: `${__dirname}/test-applications/` }); | ||
|
||
console.log(`Runnings tests for: ${testAppPaths.join(', ')}`); | ||
console.log(`Running tests for: ${testAppPaths.join(', ')}`); | ||
console.log(''); | ||
|
||
for (const testAppPath of testAppPaths) { | ||
const originalPath = resolve('test-applications', testAppPath); | ||
const tmpDirPath = await mkdtemp(join(tmpdir(), `sentry-e2e-tests-${appName}-`)); | ||
const originalPath = resolve(__dirname, 'test-applications', testAppPath); | ||
const tmpDirPath = await mkdtemp(`${tmpPrefix}${basename(testAppPath)}-`); | ||
|
||
await copyToTemp(originalPath, tmpDirPath); | ||
const cwd = tmpDirPath; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it safe to not copy
node_modules
? I'm not familiar yet with the temp dir change (which is why I requested a review from @mydea) so it might be fine, if we install deps after we copied everything to the temp dir.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be fine, we install dependencies inside of the tmp dir then. However, this should not really be necessary after this has settled - if you just run
yarn clean:all
once, all of these things will not exist in the monorepo anymore anyhow 🤔 this is why I did not add any handling for this, not sure if we want to add this complexity here...?TLDR this is only a "problem" if you have stale state from previous local runs. Running
yarn clean
should actually get rid of this fully.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, but... Usually , while developing tests, you will run them more than once (locally) and after each run you have to do
pnpm install
inside test-app dir. That's why this PR, also, removes:await asyncExec('pnpm clean:test-applications', { env, cwd: __dirname });
It is useless and annoying because test-app is being copied to tmp dir.