Skip to content

Commit 5332dbf

Browse files
committed
Run the tests on the tarball
1 parent ba9d52e commit 5332dbf

File tree

12 files changed

+99
-7
lines changed

12 files changed

+99
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
build/
33
lib/
4+
/*.tgz

test/e2e.test.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import { spawnSync } from 'node:child_process';
22
import { join } from 'node:path';
3-
import { describe, expect, test } from 'vitest';
3+
import { beforeAll, describe, expect, test } from 'vitest';
4+
import { installTarballAsDependency } from './prepare.mjs';
45

56
const __dirname = import.meta.dirname || new URL('.', import.meta.url).pathname;
67

78
describe('e2e Tests', { timeout: 20000 }, () => {
9+
beforeAll(() => {
10+
installTarballAsDependency(__dirname);
11+
});
12+
813
test('Capture stack trace from multiple threads', () => {
914
const testFile = join(__dirname, 'stack-traces.js');
1015
const result = spawnSync('node', [testFile])

test/package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "node-cpu-profiler-test",
3+
"license": "MIT",
4+
"dependencies": {
5+
"@sentry-internal/node-native-stacktrace": "file:../sentry-internal-node-native-stacktrace-0.1.0.tgz"
6+
}
7+
}

test/package.json.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "node-cpu-profiler-test",
3+
"license": "MIT",
4+
"dependencies": {
5+
"@sentry-internal/node-native-stacktrace": "{{path}}"
6+
}
7+
}

test/prepare.mjs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import { execSync, spawnSync } from 'node:child_process';
3+
import {existsSync,readFileSync, rmSync, writeFileSync } from 'node:fs';
4+
import { createRequire } from 'node:module';
5+
import { dirname, join, relative } from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
8+
const __dirname = dirname(fileURLToPath(import.meta.url));
9+
const require = createRequire(import.meta.url);
10+
const env = {...process.env, NODE_OPTIONS: '--no-deprecation'};
11+
12+
export function installTarballAsDependency(root) {
13+
const pkgJson = require('../package.json');
14+
const normalizedName = pkgJson.name.replace('@', '').replace('/', '-');
15+
16+
const tarball = join(__dirname, '..', `${normalizedName}-${pkgJson.version}.tgz`);
17+
18+
if (!existsSync(tarball)) {
19+
console.error(`Tarball not found: '${tarball}'`);
20+
console.error(`Run 'yarn build && yarn build:tarball' first`);
21+
process.exit(1);
22+
}
23+
24+
const tarballRelative = relative(root, tarball);
25+
26+
console.log('Clearing node_modules...');
27+
rmSync(join(root, 'node_modules'), { recursive: true, force: true });
28+
console.log('Clearing yarn.lock...');
29+
rmSync(join(root, 'yarn.lock'), { force: true });
30+
31+
console.log('Clearing yarn cache...');
32+
spawnSync(`yarn cache clean ${pkgJson.name}`, { shell: true, stdio: 'inherit', env });
33+
// Yarn has a bug where 'yarn cache clean X' does not remove the temp directory where the tgz is unpacked to.
34+
// This means installing from local tgz does not update when src changes are made https://github.com/yarnpkg/yarn/issues/5357
35+
const dirResult = spawnSync('yarn cache dir', { shell: true, env });
36+
const tmpDir = join(dirResult.output.toString().replace(/[,\n\r]/g, ''), '.tmp');
37+
rmSync(tmpDir, { recursive: true, force: true });
38+
39+
const pkg = readFileSync(join(root, 'package.json.template'), 'utf-8');
40+
const modified = pkg.replace(/"{{path}}"/, JSON.stringify(`file:${tarballRelative}`));
41+
writeFileSync(join(root, 'package.json'), modified);
42+
43+
console.log('Installing dependencies...');
44+
execSync('yarn install', { cwd: root });
45+
}

test/stack-traces.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Worker } = require('node:worker_threads');
22
const { longWork } = require('./long-work.js');
3-
const { registerThread } = require('../lib/index.js');
3+
const { registerThread } = require('@sentry-internal/node-native-stacktrace');
44

55
registerThread();
66

test/stalled-watchdog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { captureStackTrace, getThreadsLastSeen } = require('../lib/index.js');
1+
const { captureStackTrace, getThreadsLastSeen } = require('@sentry-internal/node-native-stacktrace');
22

33
const THRESHOLD = 500; // 1 second
44

test/stalled.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Worker } = require('node:worker_threads');
22
const { longWork } = require('./long-work.js');
3-
const { registerThread } = require('../lib/index.js');
3+
const { registerThread } = require('@sentry-internal/node-native-stacktrace');
44

55
setInterval(() => {
66
registerThread();

test/watchdog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { captureStackTrace } = require('..');
1+
const { captureStackTrace } = require('@sentry-internal/node-native-stacktrace');
22

33
setTimeout(() => {
44
console.log(JSON.stringify(captureStackTrace()));

test/worker-do-nothing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { longWork } = require('./long-work');
2-
const { registerThread } = require('../lib/index.js');
2+
const { registerThread } = require('@sentry-internal/node-native-stacktrace');
33

44
setInterval(() => {
55
registerThread();

0 commit comments

Comments
 (0)