Skip to content
This repository was archived by the owner on Aug 18, 2024. It is now read-only.

Commit e3e8502

Browse files
committed
test: crash on missing allowScripts entry
1 parent 717bb0c commit e3e8502

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

test/fixtures/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports.setup = (main, deps) => {
2020
Rimraf.sync(cwd);
2121
Mkdirp.sync(cwd);
2222
Fs.copyFileSync(Path.join(__dirname, `${main}.json`), Path.join(cwd, 'package.json'));
23+
Fs.writeFileSync(Path.join(cwd, 'res.txt'), '');
2324
delete require.cache[Path.join(cwd, 'package.json')];
2425

2526
deps.forEach((dep) => {
@@ -43,8 +44,11 @@ exports.setup = (main, deps) => {
4344
});
4445

4546
return {
46-
expectedResult: Fs.readFileSync(Path.join(__dirname, `${main}.txt`)).toString().trim(),
47-
getResults: () => {
47+
getExpectedResult: () => {
48+
49+
return Fs.readFileSync(Path.join(__dirname, `${main}.txt`)).toString().trim();
50+
},
51+
getActualResult: () => {
4852

4953
return Fs.readFileSync(output).toString().trim();
5054
},

test/fixtures/not-in-allowed.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"private": true,
3+
"name": "@example/not-in-allowed",
4+
"version": "0.0.0",
5+
"dependencies": {
6+
"@example/with-install-script": "*",
7+
"@example/with-postinstall-script": "*",
8+
"@example/without-scripts": "*"
9+
},
10+
"allowScripts": {
11+
"@example/with-postinstall-script": "*"
12+
}
13+
}

test/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,24 @@ describe('allow-scripts', () => {
4141

4242
await Allow.run({});
4343

44-
expect(fixture.getResults()).to.equal(fixture.expectedResult);
44+
expect(fixture.getActualResult()).to.equal(fixture.getExpectedResult());
4545
expect(fixture.getLog()).not.to.contain('without-scripts');
4646
expect(fixture.getLog()).not.to.contain('without-install-scripts');
4747
});
48+
49+
it('crashes on script not in allowed list', async () => {
50+
51+
const fixture = Fixtures.setup('not-in-allowed', [
52+
'with-install-script',
53+
'with-postinstall-script',
54+
'without-scripts'
55+
]);
56+
57+
await expect(Allow.run({})).to.reject('No entry for @example/with-install-script');
58+
59+
expect(fixture.getActualResult()).not.to.contain('with-postinstall-script');
60+
expect(fixture.getActualResult()).to.equal('');
61+
expect(fixture.getLog()).to.equal('');
62+
});
4863
});
4964
});

0 commit comments

Comments
 (0)