Skip to content

Commit d882fd1

Browse files
committed
build: add support for running only tests which don't use the network
1 parent ea4ba48 commit d882fd1

20 files changed

+63
-4
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
"scripts": {
1111
"build": "tsc && tsc -p tsconfig.esm.json",
1212
"build:docs": "typedoc --out docs",
13+
"jest": "jest --coverage",
14+
"lint": "prettier --check \"src/**/*.ts\"",
1315
"prepublishOnly": "npm run build",
14-
"test": "prettier --check \"src/**/*.ts\" && jest --coverage"
16+
"test": "npm run lint && npm run jest",
17+
"test:nonetwork": "npm run lint && npm run jest -- --testPathIgnorePatterns network.spec"
1518
},
1619
"files": [
1720
"dist/*",

test/FixtureDownloader.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as fs from 'fs-extra';
2+
import * as path from 'path';
3+
4+
import { Downloader } from '../src/Downloader';
5+
6+
const FIXTURE_DIR = path.resolve(__dirname, '../test/fixtures');
7+
8+
export class FixtureDownloader implements Downloader<any> {
9+
async download(url: string, targetFilePath: string) {
10+
await fs.ensureDir(path.dirname(targetFilePath));
11+
const fixtureFile = path.join(FIXTURE_DIR, path.basename(targetFilePath));
12+
if (!(await fs.pathExists(fixtureFile))) {
13+
throw new Error(`Cannot find the fixture '${fixtureFile}'`);
14+
}
15+
16+
await fs.copy(fixtureFile, targetFilePath);
17+
}
18+
}
File renamed without changes.

test/fixtures/SHASUMS256.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
92fdadf6c3927cea731be8ebeb37566d09926a3e3c83d65fb031e4424d3203e6 *chromedriver-v2.0.9-darwin-x64.zip
2+
9bd7a71f465f6881bf8b238f269c90668ac217161776ea0ed348c8e70bab2440 *electron.d.ts
3+
3cb443479f075d014ace1b944e4dc9f12b7b54771a7e0dc62fb4bf3f97792cad *electron-v2.0.10-darwin-x64.zip
4+
a9709f80ad7f52db2fd8b88b97ae26d94235cf7656ed39e00630c0df91ed0d04 *electron-v2.0.10-linux-x64.zip
5+
09e1e07b769d57c99993e1173c6ac565a43cfe2fd0ea53aeb4b2cd1839579a3c *electron-v2.0.10-win32-x64.zip
6+
80c36dea2bd2373da93192797d21eb762b26f196d3ec616082df1be74e855bd2 *electron-v2.0.3-darwin-x64.zip
7+
eac0266403045f0d22d4e8c864326cbf43f1cca1b6ed1ac037fcb06f6ec46522 *electron-v2.0.3-linux-x64.zip
8+
3f1e243fce8747c125cb61ab1834b86505b0f9f476141eedd5cfb43b4b1b8c2a *electron-v2.0.3-win32-x64.zip
9+
ff0bfe95bc2a351e09b959aab0bdab893cb33c203bfff83413c3f0989858c684 *electron-v2.0.9-darwin-x64.zip
10+
ec951354a58f63e5194ec47e10c493cf8d23c46c0caa9724bdba6d9a88d3695d *electron-v2.0.9-linux-x64.zip
11+
ae7b827f0649c5ac519080ead2d507479da90f9fbf4941d696bc3e1ae984d6b3 *electron-v2.0.9-win32-x64.zip
12+
ebb7a042d4885870cc82f510c5cb09c586ed75983a613931779bed01cfb7c657 *electron-v6.0.0-nightly.20190213-darwin-x64.zip
13+
fb9010e2301ebc24824db1842b97478a61935df741a8b716e9ae278cf234d1e2 *electron-v6.0.0-nightly.20190213-linux-x64.zip
14+
f28e3f9d2288af6abc31b19ca77a9241499fcd0600420197a9ff8e5e06182701 *electron-v6.0.0-nightly.20190213-win32-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
chromedriver-v2.0.9-darwin-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.10-darwin-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.10-linux-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.10-win32-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.3-darwin-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.3-linux-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.3-win32-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.9-darwin-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.9-linux-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v2.0.9-win32-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v6.0.0-nightly.20190213-darwin-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v6.0.0-nightly.20190213-linux-x64.zip
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
electron-v6.0.0-nightly.20190213-win32-x64.zip

test/fixtures/electron.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare namespace Electron {}

test/index.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import * as fs from 'fs-extra';
33
import * as os from 'os';
44
import * as path from 'path';
55

6+
import { FixtureDownloader } from './FixtureDownloader';
67
import { download, downloadArtifact } from '../src';
78

89
describe('Public API', () => {
9-
jest.setTimeout(120000);
10+
const downloader = new FixtureDownloader();
1011

1112
let cacheRoot: string;
1213
beforeEach(async () => {
@@ -21,6 +22,7 @@ describe('Public API', () => {
2122
it('should return a valid path to a downloaded zip file', async () => {
2223
const zipPath = await download('2.0.10', {
2324
cacheRoot,
25+
downloader,
2426
});
2527
expect(typeof zipPath).toEqual('string');
2628
expect(await fs.pathExists(zipPath)).toEqual(true);
@@ -30,6 +32,7 @@ describe('Public API', () => {
3032
it('should return a valid path to a downloaded zip file for nightly releases', async () => {
3133
const zipPath = await download('6.0.0-nightly.20190213', {
3234
cacheRoot,
35+
downloader,
3336
});
3437
expect(typeof zipPath).toEqual('string');
3538
expect(await fs.pathExists(zipPath)).toEqual(true);
@@ -39,11 +42,13 @@ describe('Public API', () => {
3942
it('should not redownload when force=false', async () => {
4043
const zipPath = await download('2.0.9', {
4144
cacheRoot,
45+
downloader,
4246
force: false,
4347
});
4448
await fs.writeFile(zipPath, 'bad content');
4549
const zipPath2 = await download('2.0.9', {
4650
cacheRoot,
51+
downloader,
4752
force: false,
4853
});
4954
expect(zipPath).toEqual(zipPath2);
@@ -53,6 +58,7 @@ describe('Public API', () => {
5358
it('should redownload when force=true', async () => {
5459
const zipPath = await download('2.0.9', {
5560
cacheRoot,
61+
downloader,
5662
force: true,
5763
});
5864
const hash = crypto
@@ -62,6 +68,7 @@ describe('Public API', () => {
6268
await fs.writeFile(zipPath, 'bad content');
6369
const zipPath2 = await download('2.0.9', {
6470
cacheRoot,
71+
downloader,
6572
force: true,
6673
});
6774
expect(zipPath).toEqual(zipPath2);
@@ -77,7 +84,7 @@ describe('Public API', () => {
7784
cacheRoot,
7885
unsafelyDisableChecksums: true,
7986
downloader: {
80-
async download(url, targetPath) {
87+
async download(url: string, targetPath: string) {
8188
expect(
8289
url.replace(process.platform, 'platform').replace(process.arch, 'arch'),
8390
).toMatchSnapshot();
@@ -97,7 +104,7 @@ describe('Public API', () => {
97104
cacheRoot,
98105
unsafelyDisableChecksums: true,
99106
downloader: {
100-
async download(url, targetPath, opts) {
107+
async download(url: string, targetPath: string, opts?: any) {
101108
expect(opts).toStrictEqual(downloadOpts);
102109
await fs.writeFile(targetPath, 'file');
103110
},
@@ -111,6 +118,7 @@ describe('Public API', () => {
111118
it('should work for electron.d.ts', async () => {
112119
const dtsPath = await downloadArtifact({
113120
cacheRoot,
121+
downloader,
114122
isGeneric: true,
115123
version: '2.0.9',
116124
artifactName: 'electron.d.ts',
@@ -122,6 +130,7 @@ describe('Public API', () => {
122130

123131
it('should work default platform/arch', async () => {
124132
await downloadArtifact({
133+
downloader,
125134
version: '2.0.3',
126135
artifactName: 'electron',
127136
});
@@ -130,6 +139,7 @@ describe('Public API', () => {
130139
it('should work for chromedriver', async () => {
131140
const driverPath = await downloadArtifact({
132141
cacheRoot,
142+
downloader,
133143
version: '2.0.9',
134144
artifactName: 'chromedriver',
135145
platform: 'darwin',

0 commit comments

Comments
 (0)