Skip to content

Commit

Permalink
chore: fix code coverage, drop ncp
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed May 2, 2019
1 parent 98f95e3 commit c9b9ea6
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/
!test/fixtures/loader/node_modules/
npm-debug.log
.coverage/
.DS_Store
.nyc_output/
.vscode/
Expand Down
22 changes: 0 additions & 22 deletions .nycrc

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@types/methods": "^1.1.0",
"@types/mocha": "^5.2.5",
"@types/mongoose": "^5.3.26",
"@types/ncp": "^2.0.1",
"@types/nock": "^10.0.0",
"@types/node": "~10.7.2",
"@types/once": "^1.4.0",
Expand All @@ -75,6 +74,7 @@
"axios": "^0.18.0",
"changelog-maker": "^2.2.2",
"codecov": "^3.0.0",
"cpy": "^7.2.0",
"express": "^4.15.2",
"glob": "^7.0.3",
"grpc": "1.20.2",
Expand All @@ -84,7 +84,6 @@
"jshint": "^2.9.1",
"linkinator": "^1.1.2",
"mocha": "^6.0.0",
"ncp": "^2.0.0",
"nock": "^10.0.0",
"nyc": "^14.0.0",
"once": "^1.4.0",
Expand Down
5 changes: 3 additions & 2 deletions scripts/check-install.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as cpy from 'cpy';
import * as path from 'path';
import { globP, ncpP, spawnP, tmpDirP } from './utils';
import { globP, spawnP, tmpDirP } from './utils';

/**
* Get the major version number of the current Node process.
Expand Down Expand Up @@ -40,7 +41,7 @@ export async function checkInstall() {
});
// Create an entry point for the package created in the temp directory
// use-module.ts is a fixture that imports the Trace Agent
await ncpP('./test/fixtures/use-module.ts', `${installDir}/index.ts`);
await cpy('./test/fixtures/use-module.ts', installDir, { rename: 'index.ts' });
// Compile it
await spawnP(`node_modules${path.sep}.bin${path.sep}tsc`, ['index.ts', '--lib', 'es2015'], {
cwd: installDir
Expand Down
2 changes: 1 addition & 1 deletion scripts/get-plugin-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flatten, globP, mkdirP, ncpP, readFileP, spawnP, tmpDirP, writeFileP } from './utils';
import { mkdirP, readFileP, spawnP, writeFileP } from './utils';

const TYPES_DIRECTORY = 'src/plugins/types';

Expand Down
11 changes: 7 additions & 4 deletions scripts/init-test-fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as cpy from 'cpy';
import * as path from 'path';
import { BUILD_DIRECTORY, statP, ncpP, spawnP, readFileP, writeFileP, mkdirP } from './utils';
import { BUILD_DIRECTORY, statP, spawnP, readFileP, writeFileP, mkdirP } from './utils';
import { readdir } from 'fs';
import * as pify from 'pify';
import * as semver from 'semver';
Expand All @@ -9,10 +10,12 @@ const readdirP: (path: string) => Promise<string[]> = pify(readdir);
export async function initTestFixtures(installPlugins: boolean) {
// Copy fixtures to build directory
const fixtureDirectories = ['./test/fixtures'];
await Promise.all(fixtureDirectories.map(async (fixtureDirectory) => {
for (const fixtureDirectory of fixtureDirectories) {
const newLocation = `${BUILD_DIRECTORY}/${path.relative('.', fixtureDirectory)}`;
await ncpP(fixtureDirectory, newLocation);
}));
await cpy(`${fixtureDirectory}/**`, BUILD_DIRECTORY, {
parents: true
});
};

if (!installPlugins) {
return;
Expand Down
5 changes: 2 additions & 3 deletions scripts/report-coverage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { BUILD_DIRECTORY, nodule, readFileP, forkP, spawnP } from './utils';
import { BUILD_DIRECTORY, nodule, forkP } from './utils';
import * as path from 'path';
import * as pify from 'pify';

export async function reportCoverage() {
await forkP(nodule('.bin/codecov'), [], {
await forkP(nodule('.bin/codecov'), [`--root=${path.resolve(BUILD_DIRECTORY, '..')}`], {
cwd: BUILD_DIRECTORY
});
}
11 changes: 7 additions & 4 deletions scripts/run-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export async function runTests(options: Options) {
let testNum = 0;
const excludedFiles = ([] as string[])
.concat(...await Promise.all((excludeGlobs || []).map(glob => globP(glob))));
const includedFiles = ([] as string[])
.concat(...await Promise.all(includeGlobs.map(glob => globP(glob))));
// const includedFiles = ([] as string[])
// .concat(...await Promise.all(includeGlobs.map(glob => globP(glob))));
const includedFiles = ['build/test/plugins/test-trace-mongoose-async-await.js'];
// Take the difference
const files = includedFiles.filter(i => excludedFiles.indexOf(i) < 0);
for (const file of files) {
Expand All @@ -28,9 +29,11 @@ export async function runTests(options: Options) {
'--reporter',
'lcov',
'--report-dir',
`./coverage/${testNum++}`,
`./.coverage/${testNum++}`,
'--exclude',
'build/test/**'
'build/test/**',
'--exclude',
'test/fixtures/**'
] : [],
nodule('mocha/bin/_mocha'),
'--require',
Expand Down
2 changes: 0 additions & 2 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mkdir, Stats, stat, readFile, writeFile } from 'fs';
import * as glob from 'glob';
import { ncp } from 'ncp';
import * as path from 'path';
import * as pify from 'pify';
import { ChildProcess, ForkOptions, fork, SpawnOptions, spawn } from 'child_process';
Expand All @@ -11,7 +10,6 @@ export const BUILD_DIRECTORY = 'build';

export const globP: (pattern: string) => Promise<string[]> = pify(glob);
export const mkdirP: (dir: string) => Promise<void> = pify(mkdir);
export const ncpP: (src: string, dest: string) => Promise<void> = pify(ncp);
export const readFileP: (path: string, encoding?: string) => Promise<Buffer|string> = pify(readFile);
export const writeFileP: (path: string, data: Buffer|string, encoding?: string) => Promise<void> = pify(writeFile);
export const statP: (path: string) => Promise<Stats> = pify(stat);
Expand Down

0 comments on commit c9b9ea6

Please sign in to comment.