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:
Ivan 2023-03-08 10:47:38 +02:00 committed by GitHub
parent 7c29869aec
commit 962678f22c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 3804 additions and 1545 deletions

View file

@ -13,11 +13,11 @@ import * as auth from '../src/authutil';
import OfficialBuilds from '../src/distributions/official_builds/official_builds';
import {INodeVersion} from '../src/distributions/base-models';
const nodeTestManifest = require('./data/versions-manifest.json');
const nodeTestDist = require('./data/node-dist-index.json');
const nodeTestDistNightly = require('./data/node-nightly-index.json');
const nodeTestDistRc = require('./data/node-rc-index.json');
const nodeV8CanaryTestDist = require('./data/v8-canary-dist-index.json');
import nodeTestManifest from './data/versions-manifest.json';
import nodeTestDist from './data/node-dist-index.json';
import nodeTestDistNightly from './data/node-nightly-index.json';
import nodeTestDistRc from './data/node-rc-index.json';
import nodeV8CanaryTestDist from './data/v8-canary-dist-index.json';
describe('setup-node', () => {
let build: OfficialBuilds;
@ -95,11 +95,11 @@ describe('setup-node', () => {
getJsonSpy.mockImplementation(url => {
let res: any;
if (url.includes('/rc')) {
res = <INodeVersion>nodeTestDistRc;
res = <INodeVersion[]>nodeTestDistRc;
} else if (url.includes('/nightly')) {
res = <INodeVersion>nodeTestDistNightly;
res = <INodeVersion[]>nodeTestDistNightly;
} else {
res = <INodeVersion>nodeTestDist;
res = <INodeVersion[]>nodeTestDist;
}
return {result: res};
@ -156,13 +156,13 @@ describe('setup-node', () => {
async (versionSpec, platform, expectedVersion, expectedLts) => {
os.platform = platform;
os.arch = 'x64';
let versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
const versions: tc.IToolRelease[] | null = await tc.getManifestFromRepo(
'actions',
'node-versions',
'mocktoken'
);
expect(versions).toBeDefined();
let match = await tc.findFromManifest(versionSpec, true, versions);
const match = await tc.findFromManifest(versionSpec, true, versions);
expect(match).toBeDefined();
expect(match?.version).toBe(expectedVersion);
expect((match as any).lts).toBe(expectedLts);
@ -177,7 +177,7 @@ describe('setup-node', () => {
inputs['node-version'] = '12';
inputs.stable = 'true';
let toolPath = path.normalize('/cache/node/12.16.1/x64');
const toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
@ -189,7 +189,7 @@ describe('setup-node', () => {
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/node/12.16.1/x64');
const toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
@ -201,16 +201,16 @@ describe('setup-node', () => {
inSpy.mockImplementation(name => inputs[name]);
let toolPath = path.normalize('/cache/node/12.16.1/x64');
const toolPath = path.normalize('/cache/node/12.16.1/x64');
findSpy.mockImplementation(() => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
const expPath = path.join(toolPath, 'bin');
expect(cnSpy).toHaveBeenCalledWith(`::add-path::${expPath}${osm.EOL}`);
});
it('handles unhandled find error and reports error', async () => {
let errMsg = 'unhandled error message';
const errMsg = 'unhandled error message';
inputs['node-version'] = '12';
findSpy.mockImplementation(() => {
@ -231,27 +231,27 @@ describe('setup-node', () => {
os.arch = 'x64';
// a version which is in the manifest
let versionSpec = '12.16.2';
let resolvedVersion = versionSpec;
const versionSpec = '12.16.2';
const resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
let expectedUrl =
const expectedUrl =
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz';
// ... but not in the local cache
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/node/12.16.2/x64');
const toolPath = path.normalize('/cache/node/12.16.2/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
const expPath = path.join(toolPath, 'bin');
expect(getExecOutputSpy).toHaveBeenCalledWith(
'node',
@ -284,7 +284,7 @@ describe('setup-node', () => {
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
let versionSpec = '11.15.0';
const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
@ -318,7 +318,7 @@ describe('setup-node', () => {
os.platform = 'linux';
os.arch = 'x64';
let versionSpec = '9.99.9';
const versionSpec = '9.99.9';
inputs['node-version'] = versionSpec;
findSpy.mockImplementation(() => '');
@ -336,13 +336,13 @@ describe('setup-node', () => {
});
it('reports a failed download', async () => {
let errMsg = 'unhandled download message';
const errMsg = 'unhandled download message';
os.platform = 'linux';
os.arch = 'x64';
// a version which is in the manifest
let versionSpec = '12.16.2';
let resolvedVersion = versionSpec;
const versionSpec = '12.16.2';
const resolvedVersion = versionSpec;
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
@ -376,7 +376,7 @@ describe('setup-node', () => {
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
let expectedUrl =
const expectedUrl =
arch === 'x64'
? `https://github.com/actions/node-versions/releases/download/${version}/node-${version}-${platform}-${arch}.zip`
: `https://nodejs.org/dist/v${version}/node-v${version}-${platform}-${arch}.${fileExtension}`;
@ -385,7 +385,7 @@ describe('setup-node', () => {
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize(`/cache/node/${version}/${arch}`);
const toolPath = path.normalize(`/cache/node/${version}/${arch}`);
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
@ -481,7 +481,7 @@ describe('setup-node', () => {
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
let versionSpec = '11';
const versionSpec = '11';
inputs['node-version'] = versionSpec;
inputs['check-latest'] = 'true';
@ -492,13 +492,13 @@ describe('setup-node', () => {
findSpy.mockImplementation(() => '');
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/node/11.11.0/x64');
const toolPath = path.normalize('/cache/node/11.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();
@ -523,7 +523,7 @@ describe('setup-node', () => {
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
let versionSpec = '12';
const versionSpec = '12';
inputs['node-version'] = versionSpec;
inputs['check-latest'] = 'true';
@ -537,13 +537,13 @@ describe('setup-node', () => {
});
dlSpy.mockImplementation(async () => '/some/temp/path');
let toolPath = path.normalize('/cache/node/12.11.0/x64');
const toolPath = path.normalize('/cache/node/12.11.0/x64');
exSpy.mockImplementation(async () => '/some/other/temp/path');
cacheSpy.mockImplementation(async () => toolPath);
await main.run();
let expPath = path.join(toolPath, 'bin');
const expPath = path.join(toolPath, 'bin');
expect(dlSpy).toHaveBeenCalled();
expect(exSpy).toHaveBeenCalled();