This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from dominykas/tests
Add tests
- Loading branch information
Showing
24 changed files
with
563 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.idea | ||
node_modules | ||
|
||
test/tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/allowed-false", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": "*", | ||
"@example/without-scripts": "*" | ||
}, | ||
"allowScripts": { | ||
"@example/with-install-script": false, | ||
"@example/with-postinstall-script": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/allowed-semver", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": "*", | ||
"@example/without-scripts": "*" | ||
}, | ||
"allowScripts": { | ||
"@example/with-install-script": "1.x.x", | ||
"@example/with-postinstall-script": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
DRY RUN ==> preinstall @example/basic | ||
|
||
DRY RUN ==> preinstall node_modules/@example/with-preinstall-script | ||
|
||
DRY RUN ==> install node_modules/@example/with-install-script | ||
|
||
DRY RUN ==> postinstall node_modules/@example/with-postinstall-script | ||
|
||
DRY RUN ==> install @example/basic | ||
|
||
DRY RUN ==> postinstall @example/basic | ||
|
||
DRY RUN ==> prepublish @example/basic | ||
|
||
DRY RUN ==> prepare @example/basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
preinstall from basic | ||
preinstall from with-preinstall-script | ||
install from with-install-script | ||
postinstall from with-postinstall-script | ||
install from basic | ||
postinstall from basic | ||
prepublish from basic | ||
prepare from basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/basic", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/with-preinstall-script": "*", | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": "*", | ||
"@example/without-scripts": "*", | ||
"@example/without-install-scripts": "*" | ||
}, | ||
"allowScripts": { | ||
"@example/with-preinstall-script": "*", | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": true | ||
}, | ||
"scripts": { | ||
"preinstall": "echo preinstall from basic >> ${OUTPUT}", | ||
"install": "echo install from basic >> ${OUTPUT}", | ||
"postinstall": "echo postinstall from basic >> ${OUTPUT}", | ||
"prepublish": "echo prepublish from basic >> ${OUTPUT}", | ||
"prepare": "echo prepare from basic >> ${OUTPUT}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/cycle-a", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/cycle-b": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/cycle-b", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/cycle-a": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/deep", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/basic": "*", | ||
"@example/with-preinstall-script": "*" | ||
}, | ||
"scripts": {}, | ||
"allowScripts": { | ||
"@example/basic": "*", | ||
"@example/with-preinstall-script": "*", | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
preinstall from with-preinstall-script | ||
preinstall from basic | ||
install from with-install-script | ||
install from basic | ||
postinstall from with-postinstall-script | ||
postinstall from basic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
'use strict'; | ||
|
||
|
||
const Fs = require('fs'); | ||
const Mkdirp = require('mkdirp'); | ||
const Path = require('path'); | ||
const Rimraf = require('rimraf'); | ||
const Sinon = require('sinon'); | ||
|
||
|
||
const internals = { | ||
restore: [] | ||
}; | ||
|
||
|
||
internals.readFile = (path) => Fs.readFileSync(path).toString().trim(); | ||
|
||
|
||
exports.expectedResults = { | ||
basicFull: internals.readFile(Path.join(__dirname, 'basic.full.txt')), | ||
basicDryRun: internals.readFile(Path.join(__dirname, 'basic.dry-run.txt')), | ||
deep: internals.readFile(Path.join(__dirname, 'deep.txt')) | ||
}; | ||
|
||
|
||
exports.setup = (main, deps) => { | ||
|
||
const cwd = Path.join(__dirname, '..', 'tmp'); | ||
const output = Path.join(cwd, 'res.txt'); | ||
|
||
Rimraf.sync(cwd); | ||
Mkdirp.sync(cwd); | ||
Fs.copyFileSync(Path.join(__dirname, `${main}.json`), Path.join(cwd, 'package.json')); | ||
Fs.writeFileSync(Path.join(cwd, 'res.txt'), ''); | ||
|
||
deps.forEach((dep) => { | ||
|
||
const pkg = require(`./${dep}.json`); | ||
|
||
Mkdirp.sync(Path.join(cwd, 'node_modules', pkg.name)); | ||
const pkgJsonPath = Path.join(cwd, 'node_modules', pkg.name, 'package.json'); | ||
Fs.writeFileSync(pkgJsonPath, JSON.stringify(Object.assign({}, pkg, { | ||
_id: `${pkg.name}@${pkg.version}` | ||
}))); | ||
}); | ||
|
||
process.chdir(cwd); | ||
|
||
const originalOutput = process.env.output; | ||
process.env.OUTPUT = output; | ||
|
||
internals.restore.push(() => { | ||
|
||
process.env.OUTPUT = originalOutput; | ||
Object.keys(require.cache).forEach((k) => { | ||
|
||
if (k.startsWith(cwd)) { | ||
delete require.cache[k]; | ||
} | ||
}); | ||
}); | ||
|
||
const log = []; | ||
const appendLog = (...items) => { | ||
|
||
// @todo: should suppress this in production code | ||
if (items[0] === 'npm notice created a lockfile as npm-shrinkwrap.json. You should commit this file.\n') { | ||
return; | ||
} | ||
|
||
log.push(items.map((i) => i || '').join(' ').replace(new RegExp(cwd, 'g'), '.')); | ||
}; | ||
|
||
Sinon.stub(console, 'info').callsFake(appendLog); | ||
Sinon.stub(console, 'log').callsFake(appendLog); | ||
Sinon.stub(console, 'warn').callsFake(appendLog); | ||
Sinon.stub(process.stderr, 'write').callsFake((data) => appendLog(data.toString())); | ||
|
||
return { | ||
cwd, | ||
getActualResult: () => internals.readFile(output), | ||
getLog: () => log.join('\n').trim() | ||
}; | ||
}; | ||
|
||
exports.restore = () => { | ||
|
||
internals.restore.forEach((restore) => restore()); | ||
internals.restore = []; | ||
Sinon.restore(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/invalid-semver", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": "*", | ||
"@example/without-scripts": "*" | ||
}, | ||
"allowScripts": { | ||
"@example/with-install-script": "not-a-semver-range", | ||
"@example/with-postinstall-script": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"private": true, | ||
"name": "@example/not-in-allowed", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"@example/with-install-script": "*", | ||
"@example/with-postinstall-script": "*", | ||
"@example/without-scripts": "*" | ||
}, | ||
"allowScripts": { | ||
"@example/with-postinstall-script": "*" | ||
} | ||
} |
Oops, something went wrong.