build: lint test code (#74)
This commit is contained in:
Родитель
cd3029cd48
Коммит
69d1fd425d
|
@ -20,10 +20,10 @@
|
|||
"docs:ci": "api-extractor run",
|
||||
"lint": "run-p lint:eslint lint:prettier",
|
||||
"lint:fix": "run-p lint:eslint:fix lint:prettier:fix",
|
||||
"lint:eslint": "eslint \"./src/**/*.ts\"",
|
||||
"lint:eslint:fix": "eslint --fix \"./src/**/*.ts\"",
|
||||
"lint:prettier": "prettier --check package.json src/**/*.ts",
|
||||
"lint:prettier:fix": "prettier --write package.json src/**/*.ts",
|
||||
"lint:eslint": "eslint \"./src/**/*.ts\" \"./tests/**/*.ts\"",
|
||||
"lint:eslint:fix": "eslint --fix \"./src/**/*.ts\" \"./tests/**/*.ts\"",
|
||||
"lint:prettier": "prettier --check package.json src/**/*.ts tests/**/*.ts",
|
||||
"lint:prettier:fix": "prettier --write package.json src/**/*.ts tests/**/*.ts",
|
||||
"make": "run-p build",
|
||||
"prepublishOnly": "npm run make",
|
||||
"start": "node dist/index.js",
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
import {
|
||||
Installer,
|
||||
FiddleFactory,
|
||||
Paths,
|
||||
Runner,
|
||||
TestResult,
|
||||
} from '../src/index';
|
||||
import { Installer, FiddleFactory, Runner, TestResult } from '../src/index';
|
||||
import child_process from 'child_process';
|
||||
import { EventEmitter } from 'events';
|
||||
import * as fs from 'fs-extra';
|
||||
|
|
|
@ -19,8 +19,12 @@ describe('BaseVersions', () => {
|
|||
it('returns the expected versions', () => {
|
||||
const { versions } = testVersions;
|
||||
expect(versions.length).toBe(1061);
|
||||
expect(versions).toContainEqual(expect.objectContaining({ version: '13.0.1' }));
|
||||
expect(versions).not.toContainEqual(expect.objectContaining({ version: '13.0.2' }));
|
||||
expect(versions).toContainEqual(
|
||||
expect.objectContaining({ version: '13.0.1' }),
|
||||
);
|
||||
expect(versions).not.toContainEqual(
|
||||
expect.objectContaining({ version: '13.0.2' }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -32,7 +36,9 @@ describe('BaseVersions', () => {
|
|||
|
||||
it('returns stable majors in sorted order', () => {
|
||||
const { stableMajors } = testVersions;
|
||||
expect(stableMajors).toEqual([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
|
||||
expect(stableMajors).toEqual([
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
]);
|
||||
});
|
||||
|
||||
it('returns supported majors in sorted order', () => {
|
||||
|
@ -67,7 +73,10 @@ describe('BaseVersions', () => {
|
|||
expect(range.shift()!.version).toBe('12.0.0');
|
||||
expect(range.pop()!.version).toBe('12.0.15');
|
||||
|
||||
range = testVersions.inRange(semver.parse('12.0.0')!, semver.parse('12.0.15')!);
|
||||
range = testVersions.inRange(
|
||||
semver.parse('12.0.0')!,
|
||||
semver.parse('12.0.15')!,
|
||||
);
|
||||
expect(range.length).toBe(16);
|
||||
expect(range.shift()!.version).toBe('12.0.0');
|
||||
expect(range.pop()!.version).toBe('12.0.15');
|
||||
|
@ -230,27 +239,26 @@ describe('ElectronVersions', () => {
|
|||
version: '0.23.0',
|
||||
},
|
||||
]);
|
||||
expect(nockScope.isDone()); // No mocks
|
||||
expect(nockScope.isDone()); // No mocks
|
||||
const { versions } = await ElectronVersions.create({ versionsCache });
|
||||
expect(versions.length).toBe(1);
|
||||
});
|
||||
|
||||
it('fetches with a missing cache', async () => {
|
||||
const scope = nockScope.get('/releases.json')
|
||||
.reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
]),
|
||||
const scope = nockScope.get('/releases.json').reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
);
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
]),
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
await fs.remove(versionsCache);
|
||||
const { versions } = await ElectronVersions.create({ versionsCache });
|
||||
expect(scope.isDone());
|
||||
|
@ -266,25 +274,24 @@ describe('ElectronVersions', () => {
|
|||
});
|
||||
|
||||
it('fetches with a stale cache', async () => {
|
||||
const scope = nockScope.get('/releases.json')
|
||||
.reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
{
|
||||
version: '0.23.2',
|
||||
},
|
||||
]),
|
||||
const scope = nockScope.get('/releases.json').reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
);
|
||||
const staleCacheMtime = (Date.now()/1000) - (5 * 60 * 60);
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
{
|
||||
version: '0.23.2',
|
||||
},
|
||||
]),
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
const staleCacheMtime = Date.now() / 1000 - 5 * 60 * 60;
|
||||
await fs.utimes(versionsCache, staleCacheMtime, staleCacheMtime);
|
||||
const { versions } = await ElectronVersions.create({ versionsCache });
|
||||
expect(scope.isDone());
|
||||
|
@ -293,7 +300,7 @@ describe('ElectronVersions', () => {
|
|||
|
||||
it('uses stale cache when fetch fails', async () => {
|
||||
const scope = nockScope.get('/releases.json').replyWithError('Error');
|
||||
const staleCacheMtime = (Date.now()/1000) - (5 * 60 * 60);
|
||||
const staleCacheMtime = Date.now() / 1000 - 5 * 60 * 60;
|
||||
await fs.utimes(versionsCache, staleCacheMtime, staleCacheMtime);
|
||||
const { versions } = await ElectronVersions.create({ versionsCache });
|
||||
expect(scope.isDone());
|
||||
|
@ -306,27 +313,26 @@ describe('ElectronVersions', () => {
|
|||
const electronVersions = await ElectronVersions.create({ versionsCache });
|
||||
expect(electronVersions.versions.length).toBe(1061);
|
||||
|
||||
const scope = nockScope.get('/releases.json')
|
||||
.reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
{
|
||||
version: '0.23.2',
|
||||
},
|
||||
{
|
||||
version: '0.23.3',
|
||||
},
|
||||
]),
|
||||
const scope = nockScope.get('/releases.json').reply(
|
||||
200,
|
||||
JSON.stringify([
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
);
|
||||
version: '0.23.0',
|
||||
},
|
||||
{
|
||||
version: '0.23.1',
|
||||
},
|
||||
{
|
||||
version: '0.23.2',
|
||||
},
|
||||
{
|
||||
version: '0.23.3',
|
||||
},
|
||||
]),
|
||||
{
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
);
|
||||
await electronVersions.fetch();
|
||||
expect(scope.isDone());
|
||||
expect(electronVersions.versions.length).toBe(4);
|
||||
|
|
Загрузка…
Ссылка в новой задаче