Skip to content
Prev Previous commit
Next Next commit
test: add a cwd cache bust test
  • Loading branch information
arcanis committed Sep 17, 2023
commit 7b2cfac4fc18a36e108c58256dfc188c86d94fd0
10 changes: 10 additions & 0 deletions test/fixtures/snapshot/cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const {
setDeserializeMainFunction,
} = require('v8').startupSnapshot;

// To make sure the cwd is present in the cache
process.cwd();

setDeserializeMainFunction(() => {
console.log(process.cwd());
});
49 changes: 49 additions & 0 deletions test/parallel/test-snapshot-cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

// This tests that user land snapshots works when the instance restored from
// the snapshot is launched with -p and -e

Comment thread
arcanis marked this conversation as resolved.
Outdated
require('../common');
const assert = require('assert');
const { spawnSync } = require('child_process');
Comment thread
aduh95 marked this conversation as resolved.
Outdated
const tmpdir = require('../common/tmpdir');
const fixtures = require('../common/fixtures');
const fs = require('fs');
const path = require('path');

tmpdir.refresh();
const blobPath = tmpdir.resolve('snapshot.blob');
const file = fixtures.path('snapshot', 'cwd.js');

const subdir = path.join(tmpdir.path, 'foo');
Comment thread
arcanis marked this conversation as resolved.
Outdated
fs.mkdirSync(subdir);

{
// Create the snapshot.
const child = spawnSync(process.execPath, [
'--snapshot-blob',
blobPath,
'--build-snapshot',
file,
], {
cwd: tmpdir.path,
encoding: `utf8`
});

assert.strictEqual(child.status, 0);
}

{
// Check a custom works.
Comment thread
arcanis marked this conversation as resolved.
Outdated
Comment thread
arcanis marked this conversation as resolved.
Outdated
const child = spawnSync(process.execPath, [
'--snapshot-blob',
blobPath,
file,
], {
cwd: subdir,
encoding: `utf8`
});

assert.strictEqual(child.status, 0);
assert.strictEqual(child.stdout, `${subdir}\n`);
}