mirror of
https://code.forgejo.org/actions/setup-node
synced 2025-06-09 21:42:20 +02:00
Add and configure ESLint and update configuration for Prettier (#703)
* Add ESLinter and update Prettier * Update eslint config * Update dependencies * Rebuild action * Update package.json * Updates docs * Update docs
This commit is contained in:
parent
7c29869aec
commit
962678f22c
31 changed files with 3804 additions and 1545 deletions
|
@ -15,11 +15,7 @@ describe('authutil tests', () => {
|
|||
let dbgSpy: jest.SpyInstance;
|
||||
|
||||
beforeAll(async () => {
|
||||
const randPath = path.join(
|
||||
Math.random()
|
||||
.toString(36)
|
||||
.substring(7)
|
||||
);
|
||||
const randPath = path.join(Math.random().toString(36).substring(7));
|
||||
console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions
|
||||
process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
|
||||
const tempDir = path.join(_runnerDir, randPath, 'temp');
|
||||
|
@ -67,10 +63,10 @@ describe('authutil tests', () => {
|
|||
}, 100000);
|
||||
|
||||
function readRcFile(rcFile: string) {
|
||||
let rc = {};
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const rc = {};
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
for (const line of contents.split(os.EOL)) {
|
||||
let parts = line.split('=');
|
||||
const parts = line.split('=');
|
||||
if (parts.length == 2) {
|
||||
rc[parts[0].trim()] = parts[1].trim();
|
||||
}
|
||||
|
@ -82,8 +78,8 @@ describe('authutil tests', () => {
|
|||
await auth.configAuthentication('https://registry.npmjs.org/', 'false');
|
||||
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
let rc = readRcFile(rcFile);
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||
expect(rc['always-auth']).toBe('false');
|
||||
});
|
||||
|
@ -92,7 +88,7 @@ describe('authutil tests', () => {
|
|||
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let rc = readRcFile(rcFile);
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||
expect(rc['always-auth']).toBe('false');
|
||||
});
|
||||
|
@ -102,7 +98,7 @@ describe('authutil tests', () => {
|
|||
await auth.configAuthentication('https://registry.npmjs.org', 'false');
|
||||
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let rc = readRcFile(rcFile);
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['@myscope:registry']).toBe('https://registry.npmjs.org/');
|
||||
expect(rc['always-auth']).toBe('false');
|
||||
});
|
||||
|
@ -111,7 +107,7 @@ describe('authutil tests', () => {
|
|||
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
||||
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let rc = readRcFile(rcFile);
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
|
||||
expect(rc['always-auth']).toBe('false');
|
||||
});
|
||||
|
@ -119,16 +115,16 @@ describe('authutil tests', () => {
|
|||
it('Sets up npmrc for always-auth true', async () => {
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let rc = readRcFile(rcFile);
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||
expect(rc['always-auth']).toBe('true');
|
||||
});
|
||||
|
||||
it('It is already set the NODE_AUTH_TOKEN export it ', async () => {
|
||||
it('is already set the NODE_AUTH_TOKEN export it', async () => {
|
||||
process.env.NODE_AUTH_TOKEN = 'foobar';
|
||||
await auth.configAuthentication('npm.pkg.github.com', 'false');
|
||||
expect(fs.statSync(rcFile)).toBeDefined();
|
||||
let rc = readRcFile(rcFile);
|
||||
const rc = readRcFile(rcFile);
|
||||
expect(rc['@ownername:registry']).toBe('npm.pkg.github.com/');
|
||||
expect(rc['always-auth']).toBe('false');
|
||||
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
|
||||
|
@ -137,7 +133,7 @@ describe('authutil tests', () => {
|
|||
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
|
||||
fs.writeFileSync(rcFile, 'registry=NNN');
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -146,7 +142,7 @@ describe('authutil tests', () => {
|
|||
it('configAuthentication should overwrite only non-scoped', async () => {
|
||||
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`@myscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -155,7 +151,7 @@ describe('authutil tests', () => {
|
|||
it('configAuthentication should add non-scoped to scoped', async () => {
|
||||
fs.writeFileSync(rcFile, '@myscope:registry=NNN');
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`@myscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -165,7 +161,7 @@ describe('authutil tests', () => {
|
|||
process.env['INPUT_SCOPE'] = 'myscope';
|
||||
fs.writeFileSync(rcFile, `@myscope:registry=NNN`);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -175,7 +171,7 @@ describe('authutil tests', () => {
|
|||
process.env['INPUT_SCOPE'] = 'myscope';
|
||||
fs.writeFileSync(rcFile, `registry=NNN${os.EOL}@myscope:registry=MMM`);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -185,7 +181,7 @@ describe('authutil tests', () => {
|
|||
process.env['INPUT_SCOPE'] = 'myscope';
|
||||
fs.writeFileSync(rcFile, `registry=MMM`);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -198,7 +194,7 @@ describe('authutil tests', () => {
|
|||
`@otherscope:registry=NNN${os.EOL}@myscope:registry=MMM`
|
||||
);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`@otherscope:registry=NNN${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
@ -208,7 +204,7 @@ describe('authutil tests', () => {
|
|||
process.env['INPUT_SCOPE'] = 'myscope';
|
||||
fs.writeFileSync(rcFile, `@otherscope:registry=MMM`);
|
||||
await auth.configAuthentication('https://registry.npmjs.org/', 'true');
|
||||
let contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
const contents = fs.readFileSync(rcFile, {encoding: 'utf8'});
|
||||
expect(contents).toBe(
|
||||
`@otherscope:registry=MMM${os.EOL}//registry.npmjs.org/:_authToken=\${NODE_AUTH_TOKEN}${os.EOL}@myscope:registry=https://registry.npmjs.org/${os.EOL}always-auth=true`
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue