Skip to content

Commit

Permalink
build: add support for running only tests which don't use the network
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed Feb 10, 2020
1 parent ea4ba48 commit d882fd1
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 4 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand Down
18 changes: 18 additions & 0 deletions test/FixtureDownloader.ts
Original file line number Diff line number Diff line change
@@ -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<any> {
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);
}
}
File renamed without changes.
14 changes: 14 additions & 0 deletions test/fixtures/SHASUMS256.txt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/fixtures/chromedriver-v2.0.9-darwin-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
chromedriver-v2.0.9-darwin-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.10-darwin-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.10-darwin-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.10-linux-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.10-linux-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.10-win32-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.10-win32-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.3-darwin-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.3-darwin-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.3-linux-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.3-linux-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.3-win32-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.3-win32-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.9-darwin-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.9-darwin-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.9-linux-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.9-linux-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron-v2.0.9-win32-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v2.0.9-win32-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v6.0.0-nightly.20190213-darwin-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v6.0.0-nightly.20190213-linux-x64.zip
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
electron-v6.0.0-nightly.20190213-win32-x64.zip
1 change: 1 addition & 0 deletions test/fixtures/electron.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare namespace Electron {}
16 changes: 13 additions & 3 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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');
},
Expand All @@ -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',
Expand All @@ -122,6 +130,7 @@ describe('Public API', () => {

it('should work default platform/arch', async () => {
await downloadArtifact({
downloader,
version: '2.0.3',
artifactName: 'electron',
});
Expand All @@ -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',
Expand Down

0 comments on commit d882fd1

Please sign in to comment.