From d882fd16c4063d33c1924c25713a7c09c26c6c5e Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Thu, 19 Dec 2019 14:09:23 -0800 Subject: [PATCH] build: add support for running only tests which don't use the network --- package.json | 5 ++++- test/FixtureDownloader.ts | 18 ++++++++++++++++++ ...r.spec.ts => GotDownloader.network.spec.ts} | 0 ...snap => GotDownloader.network.spec.ts.snap} | 0 test/fixtures/SHASUMS256.txt | 14 ++++++++++++++ .../chromedriver-v2.0.9-darwin-x64.zip | 1 + test/fixtures/electron-v2.0.10-darwin-x64.zip | 1 + test/fixtures/electron-v2.0.10-linux-x64.zip | 1 + test/fixtures/electron-v2.0.10-win32-x64.zip | 1 + test/fixtures/electron-v2.0.3-darwin-x64.zip | 1 + test/fixtures/electron-v2.0.3-linux-x64.zip | 1 + test/fixtures/electron-v2.0.3-win32-x64.zip | 1 + test/fixtures/electron-v2.0.9-darwin-x64.zip | 1 + test/fixtures/electron-v2.0.9-linux-x64.zip | 1 + test/fixtures/electron-v2.0.9-win32-x64.zip | 1 + ...tron-v6.0.0-nightly.20190213-darwin-x64.zip | 1 + ...ctron-v6.0.0-nightly.20190213-linux-x64.zip | 1 + ...ctron-v6.0.0-nightly.20190213-win32-x64.zip | 1 + test/fixtures/electron.d.ts | 1 + test/index.spec.ts | 16 +++++++++++++--- 20 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 test/FixtureDownloader.ts rename test/{GotDownloader.spec.ts => GotDownloader.network.spec.ts} (100%) rename test/__snapshots__/{GotDownloader.spec.ts.snap => GotDownloader.network.spec.ts.snap} (100%) create mode 100644 test/fixtures/SHASUMS256.txt create mode 100644 test/fixtures/chromedriver-v2.0.9-darwin-x64.zip create mode 100644 test/fixtures/electron-v2.0.10-darwin-x64.zip create mode 100644 test/fixtures/electron-v2.0.10-linux-x64.zip create mode 100644 test/fixtures/electron-v2.0.10-win32-x64.zip create mode 100644 test/fixtures/electron-v2.0.3-darwin-x64.zip create mode 100644 test/fixtures/electron-v2.0.3-linux-x64.zip create mode 100644 test/fixtures/electron-v2.0.3-win32-x64.zip create mode 100644 test/fixtures/electron-v2.0.9-darwin-x64.zip create mode 100644 test/fixtures/electron-v2.0.9-linux-x64.zip create mode 100644 test/fixtures/electron-v2.0.9-win32-x64.zip create mode 100644 test/fixtures/electron-v6.0.0-nightly.20190213-darwin-x64.zip create mode 100644 test/fixtures/electron-v6.0.0-nightly.20190213-linux-x64.zip create mode 100644 test/fixtures/electron-v6.0.0-nightly.20190213-win32-x64.zip create mode 100644 test/fixtures/electron.d.ts diff --git a/package.json b/package.json index 21ec5d97f..fea551ef7 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,11 @@ "scripts": { "build": "tsc && tsc -p tsconfig.esm.json", "build:docs": "typedoc --out docs", + "jest": "jest --coverage", + "lint": "prettier --check \"src/**/*.ts\"", "prepublishOnly": "npm run build", - "test": "prettier --check \"src/**/*.ts\" && jest --coverage" + "test": "npm run lint && npm run jest", + "test:nonetwork": "npm run lint && npm run jest -- --testPathIgnorePatterns network.spec" }, "files": [ "dist/*", diff --git a/test/FixtureDownloader.ts b/test/FixtureDownloader.ts new file mode 100644 index 000000000..3c1f78ad3 --- /dev/null +++ b/test/FixtureDownloader.ts @@ -0,0 +1,18 @@ +import * as fs from 'fs-extra'; +import * as path from 'path'; + +import { Downloader } from '../src/Downloader'; + +const FIXTURE_DIR = path.resolve(__dirname, '../test/fixtures'); + +export class FixtureDownloader implements Downloader { + async download(url: string, targetFilePath: string) { + await fs.ensureDir(path.dirname(targetFilePath)); + const fixtureFile = path.join(FIXTURE_DIR, path.basename(targetFilePath)); + if (!(await fs.pathExists(fixtureFile))) { + throw new Error(`Cannot find the fixture '${fixtureFile}'`); + } + + await fs.copy(fixtureFile, targetFilePath); + } +} diff --git a/test/GotDownloader.spec.ts b/test/GotDownloader.network.spec.ts similarity index 100% rename from test/GotDownloader.spec.ts rename to test/GotDownloader.network.spec.ts diff --git a/test/__snapshots__/GotDownloader.spec.ts.snap b/test/__snapshots__/GotDownloader.network.spec.ts.snap similarity index 100% rename from test/__snapshots__/GotDownloader.spec.ts.snap rename to test/__snapshots__/GotDownloader.network.spec.ts.snap diff --git a/test/fixtures/SHASUMS256.txt b/test/fixtures/SHASUMS256.txt new file mode 100644 index 000000000..297ce240a --- /dev/null +++ b/test/fixtures/SHASUMS256.txt @@ -0,0 +1,14 @@ +92fdadf6c3927cea731be8ebeb37566d09926a3e3c83d65fb031e4424d3203e6 *chromedriver-v2.0.9-darwin-x64.zip +9bd7a71f465f6881bf8b238f269c90668ac217161776ea0ed348c8e70bab2440 *electron.d.ts +3cb443479f075d014ace1b944e4dc9f12b7b54771a7e0dc62fb4bf3f97792cad *electron-v2.0.10-darwin-x64.zip +a9709f80ad7f52db2fd8b88b97ae26d94235cf7656ed39e00630c0df91ed0d04 *electron-v2.0.10-linux-x64.zip +09e1e07b769d57c99993e1173c6ac565a43cfe2fd0ea53aeb4b2cd1839579a3c *electron-v2.0.10-win32-x64.zip +80c36dea2bd2373da93192797d21eb762b26f196d3ec616082df1be74e855bd2 *electron-v2.0.3-darwin-x64.zip +eac0266403045f0d22d4e8c864326cbf43f1cca1b6ed1ac037fcb06f6ec46522 *electron-v2.0.3-linux-x64.zip +3f1e243fce8747c125cb61ab1834b86505b0f9f476141eedd5cfb43b4b1b8c2a *electron-v2.0.3-win32-x64.zip +ff0bfe95bc2a351e09b959aab0bdab893cb33c203bfff83413c3f0989858c684 *electron-v2.0.9-darwin-x64.zip +ec951354a58f63e5194ec47e10c493cf8d23c46c0caa9724bdba6d9a88d3695d *electron-v2.0.9-linux-x64.zip +ae7b827f0649c5ac519080ead2d507479da90f9fbf4941d696bc3e1ae984d6b3 *electron-v2.0.9-win32-x64.zip +ebb7a042d4885870cc82f510c5cb09c586ed75983a613931779bed01cfb7c657 *electron-v6.0.0-nightly.20190213-darwin-x64.zip +fb9010e2301ebc24824db1842b97478a61935df741a8b716e9ae278cf234d1e2 *electron-v6.0.0-nightly.20190213-linux-x64.zip +f28e3f9d2288af6abc31b19ca77a9241499fcd0600420197a9ff8e5e06182701 *electron-v6.0.0-nightly.20190213-win32-x64.zip diff --git a/test/fixtures/chromedriver-v2.0.9-darwin-x64.zip b/test/fixtures/chromedriver-v2.0.9-darwin-x64.zip new file mode 100644 index 000000000..0393dd7e4 --- /dev/null +++ b/test/fixtures/chromedriver-v2.0.9-darwin-x64.zip @@ -0,0 +1 @@ +chromedriver-v2.0.9-darwin-x64.zip diff --git a/test/fixtures/electron-v2.0.10-darwin-x64.zip b/test/fixtures/electron-v2.0.10-darwin-x64.zip new file mode 100644 index 000000000..174c60346 --- /dev/null +++ b/test/fixtures/electron-v2.0.10-darwin-x64.zip @@ -0,0 +1 @@ +electron-v2.0.10-darwin-x64.zip diff --git a/test/fixtures/electron-v2.0.10-linux-x64.zip b/test/fixtures/electron-v2.0.10-linux-x64.zip new file mode 100644 index 000000000..c253c83f6 --- /dev/null +++ b/test/fixtures/electron-v2.0.10-linux-x64.zip @@ -0,0 +1 @@ +electron-v2.0.10-linux-x64.zip diff --git a/test/fixtures/electron-v2.0.10-win32-x64.zip b/test/fixtures/electron-v2.0.10-win32-x64.zip new file mode 100644 index 000000000..ce564467b --- /dev/null +++ b/test/fixtures/electron-v2.0.10-win32-x64.zip @@ -0,0 +1 @@ +electron-v2.0.10-win32-x64.zip diff --git a/test/fixtures/electron-v2.0.3-darwin-x64.zip b/test/fixtures/electron-v2.0.3-darwin-x64.zip new file mode 100644 index 000000000..f855d2561 --- /dev/null +++ b/test/fixtures/electron-v2.0.3-darwin-x64.zip @@ -0,0 +1 @@ +electron-v2.0.3-darwin-x64.zip diff --git a/test/fixtures/electron-v2.0.3-linux-x64.zip b/test/fixtures/electron-v2.0.3-linux-x64.zip new file mode 100644 index 000000000..fe58ea3c0 --- /dev/null +++ b/test/fixtures/electron-v2.0.3-linux-x64.zip @@ -0,0 +1 @@ +electron-v2.0.3-linux-x64.zip diff --git a/test/fixtures/electron-v2.0.3-win32-x64.zip b/test/fixtures/electron-v2.0.3-win32-x64.zip new file mode 100644 index 000000000..02eda88c2 --- /dev/null +++ b/test/fixtures/electron-v2.0.3-win32-x64.zip @@ -0,0 +1 @@ +electron-v2.0.3-win32-x64.zip diff --git a/test/fixtures/electron-v2.0.9-darwin-x64.zip b/test/fixtures/electron-v2.0.9-darwin-x64.zip new file mode 100644 index 000000000..852194b97 --- /dev/null +++ b/test/fixtures/electron-v2.0.9-darwin-x64.zip @@ -0,0 +1 @@ +electron-v2.0.9-darwin-x64.zip diff --git a/test/fixtures/electron-v2.0.9-linux-x64.zip b/test/fixtures/electron-v2.0.9-linux-x64.zip new file mode 100644 index 000000000..6f8341962 --- /dev/null +++ b/test/fixtures/electron-v2.0.9-linux-x64.zip @@ -0,0 +1 @@ +electron-v2.0.9-linux-x64.zip diff --git a/test/fixtures/electron-v2.0.9-win32-x64.zip b/test/fixtures/electron-v2.0.9-win32-x64.zip new file mode 100644 index 000000000..d4cc754bb --- /dev/null +++ b/test/fixtures/electron-v2.0.9-win32-x64.zip @@ -0,0 +1 @@ +electron-v2.0.9-win32-x64.zip diff --git a/test/fixtures/electron-v6.0.0-nightly.20190213-darwin-x64.zip b/test/fixtures/electron-v6.0.0-nightly.20190213-darwin-x64.zip new file mode 100644 index 000000000..1722fd82a --- /dev/null +++ b/test/fixtures/electron-v6.0.0-nightly.20190213-darwin-x64.zip @@ -0,0 +1 @@ +electron-v6.0.0-nightly.20190213-darwin-x64.zip diff --git a/test/fixtures/electron-v6.0.0-nightly.20190213-linux-x64.zip b/test/fixtures/electron-v6.0.0-nightly.20190213-linux-x64.zip new file mode 100644 index 000000000..49607bd8e --- /dev/null +++ b/test/fixtures/electron-v6.0.0-nightly.20190213-linux-x64.zip @@ -0,0 +1 @@ +electron-v6.0.0-nightly.20190213-linux-x64.zip diff --git a/test/fixtures/electron-v6.0.0-nightly.20190213-win32-x64.zip b/test/fixtures/electron-v6.0.0-nightly.20190213-win32-x64.zip new file mode 100644 index 000000000..fff210ebe --- /dev/null +++ b/test/fixtures/electron-v6.0.0-nightly.20190213-win32-x64.zip @@ -0,0 +1 @@ +electron-v6.0.0-nightly.20190213-win32-x64.zip diff --git a/test/fixtures/electron.d.ts b/test/fixtures/electron.d.ts new file mode 100644 index 000000000..ea4610a07 --- /dev/null +++ b/test/fixtures/electron.d.ts @@ -0,0 +1 @@ +declare namespace Electron {} diff --git a/test/index.spec.ts b/test/index.spec.ts index 576a33f9e..ab9f4b3ea 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -3,10 +3,11 @@ import * as fs from 'fs-extra'; import * as os from 'os'; import * as path from 'path'; +import { FixtureDownloader } from './FixtureDownloader'; import { download, downloadArtifact } from '../src'; describe('Public API', () => { - jest.setTimeout(120000); + const downloader = new FixtureDownloader(); let cacheRoot: string; beforeEach(async () => { @@ -21,6 +22,7 @@ describe('Public API', () => { it('should return a valid path to a downloaded zip file', async () => { const zipPath = await download('2.0.10', { cacheRoot, + downloader, }); expect(typeof zipPath).toEqual('string'); expect(await fs.pathExists(zipPath)).toEqual(true); @@ -30,6 +32,7 @@ describe('Public API', () => { it('should return a valid path to a downloaded zip file for nightly releases', async () => { const zipPath = await download('6.0.0-nightly.20190213', { cacheRoot, + downloader, }); expect(typeof zipPath).toEqual('string'); expect(await fs.pathExists(zipPath)).toEqual(true); @@ -39,11 +42,13 @@ describe('Public API', () => { it('should not redownload when force=false', async () => { const zipPath = await download('2.0.9', { cacheRoot, + downloader, force: false, }); await fs.writeFile(zipPath, 'bad content'); const zipPath2 = await download('2.0.9', { cacheRoot, + downloader, force: false, }); expect(zipPath).toEqual(zipPath2); @@ -53,6 +58,7 @@ describe('Public API', () => { it('should redownload when force=true', async () => { const zipPath = await download('2.0.9', { cacheRoot, + downloader, force: true, }); const hash = crypto @@ -62,6 +68,7 @@ describe('Public API', () => { await fs.writeFile(zipPath, 'bad content'); const zipPath2 = await download('2.0.9', { cacheRoot, + downloader, force: true, }); expect(zipPath).toEqual(zipPath2); @@ -77,7 +84,7 @@ describe('Public API', () => { cacheRoot, unsafelyDisableChecksums: true, downloader: { - async download(url, targetPath) { + async download(url: string, targetPath: string) { expect( url.replace(process.platform, 'platform').replace(process.arch, 'arch'), ).toMatchSnapshot(); @@ -97,7 +104,7 @@ describe('Public API', () => { cacheRoot, unsafelyDisableChecksums: true, downloader: { - async download(url, targetPath, opts) { + async download(url: string, targetPath: string, opts?: any) { expect(opts).toStrictEqual(downloadOpts); await fs.writeFile(targetPath, 'file'); }, @@ -111,6 +118,7 @@ describe('Public API', () => { it('should work for electron.d.ts', async () => { const dtsPath = await downloadArtifact({ cacheRoot, + downloader, isGeneric: true, version: '2.0.9', artifactName: 'electron.d.ts', @@ -122,6 +130,7 @@ describe('Public API', () => { it('should work default platform/arch', async () => { await downloadArtifact({ + downloader, version: '2.0.3', artifactName: 'electron', }); @@ -130,6 +139,7 @@ describe('Public API', () => { it('should work for chromedriver', async () => { const driverPath = await downloadArtifact({ cacheRoot, + downloader, version: '2.0.9', artifactName: 'chromedriver', platform: 'darwin',