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

Commit 226e5b6

Browse files
committed
test: when nothing allowed; when semver range is invalid
1 parent fc48f25 commit 226e5b6

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"url": "https://github.com/dominykas/allow-scripts.git"
88
},
99
"scripts": {
10-
"test": "lab -L -t 83 -m 5000"
10+
"test": "lab -L -t 86 -m 5000"
1111
},
1212
"bin": {
1313
"allow-scripts": "./bin/allow-scripts.js"

test/fixtures/allowed-semver.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
3-
"name": "@example/allowed-false",
3+
"name": "@example/allowed-semver",
44
"version": "0.0.0",
55
"dependencies": {
66
"@example/with-install-script": "*",

test/fixtures/invalid-semver.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"private": true,
3+
"name": "@example/invalid-semver",
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-install-script": "not-a-semver-range",
12+
"@example/with-postinstall-script": "*"
13+
}
14+
}

test/fixtures/nothing-allowed.json

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

test/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,33 @@ describe('allow-scripts', () => {
8585
expect(fixture.getActualResult()).to.equal('postinstall from with-postinstall-script');
8686
expect(fixture.getLog()).to.contain('skip node_modules/@example/with-install-script (because 0.0.0 is outside of allowed range: 1.x.x)');
8787
});
88+
89+
it('crashes on invalid semver range', async () => {
90+
91+
const fixture = Fixtures.setup('invalid-semver', [
92+
'with-install-script',
93+
'with-postinstall-script',
94+
'without-scripts'
95+
]);
96+
97+
await expect(Allow.run({})).to.reject('Invalid version range in allowScripts[@example/with-install-script]: not-a-semver-range');
98+
99+
expect(fixture.getActualResult()).to.equal('');
100+
expect(fixture.getLog()).to.equal('');
101+
});
102+
103+
it('crashes on missing allowScripts section', async () => {
104+
105+
const fixture = Fixtures.setup('nothing-allowed', [
106+
'with-install-script',
107+
'with-postinstall-script',
108+
'without-scripts'
109+
]);
110+
111+
await expect(Allow.run({})).to.reject('No entry for @example/with-install-script');
112+
113+
expect(fixture.getActualResult()).to.equal('');
114+
expect(fixture.getLog()).to.equal('');
115+
});
88116
});
89117
});

0 commit comments

Comments
 (0)