mirror of
https://github.com/actions/setup-node.git
synced 2025-06-28 21:53:48 +00:00
adds the ability to set ignore-scripts in npm config
This commit is contained in:
parent
e54c83ad43
commit
8d3d0041fe
8 changed files with 122 additions and 3 deletions
46
__tests__/ignore-scripts.test.ts
Normal file
46
__tests__/ignore-scripts.test.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import * as ignorescripts from '../src/ignore-scripts';
|
||||
import {getNpmrcLocation} from '../src/util';
|
||||
|
||||
let rcFile: string;
|
||||
|
||||
describe('ignore-scripts tests', () => {
|
||||
const runnerDir = path.join(__dirname, 'runner');
|
||||
|
||||
beforeEach(async () => {
|
||||
rcFile = getNpmrcLocation();
|
||||
}, 5000);
|
||||
|
||||
afterEach(async () => {
|
||||
fs.unlinkSync(rcFile);
|
||||
rcFile = getNpmrcLocation();
|
||||
}, 10000);
|
||||
|
||||
it('sets the value to true according to input', async () => {
|
||||
ignorescripts.ignoreScriptsInNpmConfig('true');
|
||||
const rcContents = fs.readFileSync(rcFile).toString();
|
||||
expect(rcContents).toMatch('\nignore-scripts=true\n');
|
||||
});
|
||||
|
||||
it('sets the value to false according to input', async () => {
|
||||
ignorescripts.ignoreScriptsInNpmConfig('false');
|
||||
const rcContents = fs.readFileSync(rcFile).toString();
|
||||
expect(rcContents).toMatch('\nignore-scripts=false\n');
|
||||
});
|
||||
|
||||
it('defaults to false on empty input', async () => {
|
||||
ignorescripts.ignoreScriptsInNpmConfig('');
|
||||
const rcContents = fs.readFileSync(rcFile).toString();
|
||||
expect(rcContents).toMatch('\nignore-scripts=false\n');
|
||||
});
|
||||
|
||||
it('preserves existing npmrc file contents', async () => {
|
||||
fs.writeFileSync(getNpmrcLocation(), 'something\nwhatever\nstuff');
|
||||
ignorescripts.ignoreScriptsInNpmConfig('true');
|
||||
const rcContents = fs.readFileSync(rcFile).toString();
|
||||
expect(rcContents).toMatch(
|
||||
'something\nwhatever\nstuff\nignore-scripts=true\n'
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue