Skip to content

Commit

Permalink
refactor: make running tests better with --fast and --match utils
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Nov 24, 2018
1 parent a05e2dc commit fb776e1
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 723 deletions.
2 changes: 1 addition & 1 deletion ci/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ bolt
bolt build
bolt lint

DEBUG=electron-installer-snap:snapcraft CI=true bolt ws test -- --installer=$NODE_INSTALLER
DEBUG=electron-installer-snap:snapcraft CI=true bolt test -- --installer=$NODE_INSTALLER
4 changes: 3 additions & 1 deletion mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
--require ts-node/register
--require @babel/register
--require ../../../tools/test-setup.js
--require ../../../tools/test-setup.ts
--timeout 800000
--recursive
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"docs:deploy": "ts-node tools/sync-readmes.ts && bolt docs && ts-node tools/copy-now.ts && cd docs && now && now alias",
"docs:deploy:ci": "ts-node tools/sync-readmes.ts && bolt docs && ts-node tools/copy-now.ts && cd docs && now --token $NOW_TOKEN && now alias --token $NOW_TOKEN",
"lint": "ts-node tools/link-ts.ts && bolt ws exec -- node_modules/.bin/tslint src/**/*.ts test/**/*.ts",
"test": "bolt ws run test"
"test": "TS_NODE_FILES=true yarn run mocha './tools/test-globber.ts' --opts mocha.opts"
},
"dependencies": {
"@octokit/rest": "^15.2.6",
Expand Down Expand Up @@ -112,6 +112,7 @@
"@types/lodash.template": "^4.4.4",
"@types/log-symbols": "^2.0.0",
"@types/mime-types": "^2.1.0",
"@types/minimist": "^1.2.0",
"@types/mocha": "^5.1.0",
"@types/node": "10.12.0",
"@types/node-fetch": "^2.1.2",
Expand All @@ -122,6 +123,7 @@
"@types/proxyquire": "^1.3.28",
"@types/semver": "^5.5.0",
"@types/sinon": "5.0.5",
"@types/username": "^3.0.0",
"@types/webpack": "4.4.17",
"@types/webpack-dev-middleware": "^2.0.1",
"@types/webpack-hot-middleware": "^2.16.3",
Expand All @@ -134,12 +136,10 @@
"coveralls": "^3.0.0",
"cross-env": "^5.0.0",
"cz-customizable": "^5.0.0",
"esdoc": "^1.0.1",
"esdoc-importpath-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0",
"fetch-mock": "^6.0.0",
"generate-changelog": "^1.0.2",
"listr": "^0.14.1",
"minimist": "^1.2.0",
"mocha": "^5.0.0",
"nodemon": "^1.11.0",
"nyc": "^13.0.1",
Expand Down
28 changes: 0 additions & 28 deletions packages/api/core/.esdoc.json

This file was deleted.

8 changes: 0 additions & 8 deletions packages/api/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
"repository": "https:/electron-userland/electron-forge",
"main": "dist/api/index.js",
"typings": "dist/api/index.d.ts",
"scripts": {
"docs": "esdoc",
"test:fast": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts --opts ../../../mocha.opts",
"test": "mocha --require ts-node/register test/**/*_spec.ts test/**/**/*_spec.ts test/slow/*_spec_slow.ts --opts ../../../mocha.opts"
},
"author": "Samuel Attard",
"license": "MIT",
"devDependencies": {
Expand All @@ -25,9 +20,6 @@
"asar": "^0.14.0",
"chai": "4.2.0",
"chai-as-promised": "^7.0.0",
"esdoc": "^1.0.1",
"esdoc-importpath-plugin": "^1.0.0",
"esdoc-standard-plugin": "^1.0.0",
"fetch-mock": "^6.0.0",
"mocha": "^5.0.0",
"proxyquire": "^2.0.1",
Expand Down
18 changes: 0 additions & 18 deletions packages/api/core/typings/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,18 +0,0 @@
declare module 'yarn-or-npm' {
const yon: () => 'yarn' | 'npm';
export default yon;
}

declare module 'sudo-prompt' {
export const exec: () => void;
}

declare module 'resolve-package' {
const resolve: (packageName: string) => Promise<string>;
export default resolve;
}

declare module 'username' {
const username: () => Promise<string>;
export default username;
}
6 changes: 0 additions & 6 deletions packages/installer/darwin/typings/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
declare module 'sudo-prompt' {
type Exec = (command: string, app: {
name: string;
}) => void;
export const exec: Exec;
}
6 changes: 0 additions & 6 deletions packages/installer/linux/typings/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
declare module 'sudo-prompt' {
type Exec = (command: string, app: {
name: string;
}) => void;
export const exec: Exec;
}
6 changes: 5 additions & 1 deletion packages/maker/appx/src/util/author-name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import parseAuthor, { AuthorType } from 'parse-author';
import parseAuthor from 'parse-author';

type AuthorType = string | {
name: string;
} | undefined;

export default function getNameFromAuthor(author: AuthorType) {
let publisher: AuthorType = author || '';
Expand Down
39 changes: 0 additions & 39 deletions packages/maker/appx/typings/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,39 +0,0 @@
declare module 'parse-author' {
export type AuthorType = string | {
name: string;
} | undefined;
interface ParseAuthor {
(author: AuthorType): AuthorType;
}
const parseAuthor: ParseAuthor;
export default parseAuthor;
}

declare module 'electron-windows-store' {
const run: (opts: any) => Promise<void>;
export default run;
}

declare module 'electron-windows-store/lib/sign' {
export const isValidPublisherName: (name: string) => boolean;
export const makeCert: (opts: MakerCertOptions) => Promise<string>;

interface MakerCertOptions {
publisherName: string;
certFilePath: string;
certFileName: string;
install: boolean;
program: any;
}
}

declare module 'cross-spawn/lib/util/resolveCommand' {
interface Opts {
command: string;
options: {
cwd: string | null;
};
}
const resolveCommand: (opts: Opts, work: boolean) => string;
export default resolveCommand;
}
6 changes: 5 additions & 1 deletion packages/maker/wix/src/util/author-name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import parseAuthor, { AuthorType } from 'parse-author';
import parseAuthor from 'parse-author';

type AuthorType = string | {
name: string;
} | undefined;

export default function getNameFromAuthor(author: AuthorType) {
let publisher: AuthorType = author || '';
Expand Down
10 changes: 0 additions & 10 deletions packages/maker/wix/typings/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
declare module 'parse-author' {
export type AuthorType = string | {
name: string;
} | undefined;
interface ParseAuthor {
(author: AuthorType): AuthorType;
}
const parseAuthor: ParseAuthor;
export default parseAuthor;
}
16 changes: 5 additions & 11 deletions tools/position-docs.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import * as fs from 'fs-extra';
import Glob from 'glob';
import * as path from 'path';
import { getPackageInfo } from './utils';

const DOCS_PATH = path.resolve(__dirname, '..', 'docs');
const BASE_DIR = path.resolve(__dirname, '..');
const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');

(async () => {
const packageDirs = [];

for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
packageDirs.push(path.resolve(PACKAGES_DIR, subDir, packageDir));
}
}
const packages = await getPackageInfo();

let copiedAssets = false;
await fs.remove(path.resolve(DOCS_PATH, 'assets'));
await fs.remove(path.resolve(DOCS_PATH));
for (const dir of packageDirs) {
for (const p of packages) {
const dir = p.path;
const subPath = path.posix.join(path.basename(path.dirname(dir)), path.basename(dir));
const docPath = path.resolve(DOCS_PATH, subPath);
if (!copiedAssets) {
Expand All @@ -38,7 +32,7 @@ const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');
.replace(/=\"[^"]*assets\//gi, '="/assets/')
.replace(/(<a href="(?!(?:https?:\/\/)|\/|\#))(.+?)"/gi, (subString, m1: string, m2: string) => {
return `${m1}/${path.posix.join(subPath, relative, m2)}"`;
})
}),
);
}
}
Expand Down
25 changes: 25 additions & 0 deletions tools/test-globber.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import minimist from 'minimist';
import * as path from 'path';
import { getPackageInfoSync } from './utils';
import Glob from 'glob';

const argv = minimist(
process.argv.slice(
process.argv.findIndex(arg => arg === 'mocha.opts'),
),
);

const isFast = argv.fast;

const packages = getPackageInfoSync();
const testFiles: string[] = [];

for (const p of packages) {
if (argv.match && !p.name.includes(argv.match)) continue;

testFiles.push(...Glob.sync(path.resolve(p.path, 'test', '**', `*_spec${isFast ? '' : '*'}.ts`)));
}

for (const f of testFiles) {
require(f);
}
4 changes: 0 additions & 4 deletions tools/test-setup.js

This file was deleted.

4 changes: 4 additions & 0 deletions tools/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as chai from 'chai';
import chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised);
42 changes: 42 additions & 0 deletions tools/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as fs from 'fs-extra';
import * as path from 'path';

const BASE_DIR = path.resolve(__dirname, '..');
const PACKAGES_DIR = path.resolve(BASE_DIR, 'packages');

export interface Package {
path: string;
name: string;
}

export const getPackageInfo = async () => {
const packages: Package[] = [];

for (const subDir of await fs.readdir(PACKAGES_DIR)) {
for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
const packagePath = path.resolve(PACKAGES_DIR, subDir, packageDir);
packages.push({
path: packagePath,
name: (await fs.readJson(path.resolve(packagePath, 'package.json'))).name,
});
}
}

return packages;
};

export const getPackageInfoSync = () => {
const packages: Package[] = [];

for (const subDir of fs.readdirSync(PACKAGES_DIR)) {
for (const packageDir of fs.readdirSync(path.resolve(PACKAGES_DIR, subDir))) {
const packagePath = path.resolve(PACKAGES_DIR, subDir, packageDir);
packages.push({
path: packagePath,
name: (fs.readJsonSync(path.resolve(packagePath, 'package.json'))).name,
});
}
}

return packages;
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"es7"
],
"sourceMap": true,
"rootDir": "src",
"rootDir": ".",
"experimentalDecorators": true,
"strict": true,
"esModuleInterop": true,
Expand Down
1 change: 1 addition & 0 deletions typings/cross-spawn/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'cross-spawn/lib/util/resolveCommand';
17 changes: 17 additions & 0 deletions typings/electron-windows-store/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
declare module 'electron-windows-store' {
const run: (opts: any) => Promise<void>;
export default run;
}

declare module 'electron-windows-store/lib/sign' {
export const isValidPublisherName: (name: string) => boolean;
export const makeCert: (opts: MakerCertOptions) => Promise<string>;

interface MakerCertOptions {
publisherName: string;
certFilePath: string;
certFileName: string;
install: boolean;
program: any;
}
}
10 changes: 10 additions & 0 deletions typings/parse-author/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare module 'parse-author' {
type AuthorType = string | {
name: string;
} | undefined;
interface ParseAuthor {
(author: AuthorType): AuthorType;
}
const parseAuthor: ParseAuthor;
export default parseAuthor;
}
4 changes: 4 additions & 0 deletions typings/resolve-package/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'resolve-package' {
const resolve: (packageName: string) => Promise<string>;
export default resolve;
}
3 changes: 3 additions & 0 deletions typings/sudo-prompt/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare module 'sudo-prompt' {
export const exec: () => void;
}
4 changes: 4 additions & 0 deletions typings/yarn-or-npm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'yarn-or-npm' {
const yon: () => 'yarn' | 'npm';
export default yon;
}
Loading

0 comments on commit fb776e1

Please sign in to comment.