Skip to content

Commit

Permalink
chore: remove external-dependency rimraf
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhu256 committed Nov 19, 2020
1 parent ebe92de commit 47daa99
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 31 deletions.
4 changes: 2 additions & 2 deletions bin/c8.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const foreground = require('foreground-child')
const { outputReport } = require('../lib/commands/report')
const { promises } = require('fs')
const { promisify } = require('util')
const rimraf = require('rimraf')
const rmrf = require('../lib/rmrf')
const {
buildYargs,
hideInstrumenteeArgs,
Expand All @@ -29,7 +29,7 @@ async function run () {
}

if (argv.clean) {
await promisify(rimraf)(argv.tempDirectory)
await promisify(rmrf)(argv.tempDirectory)
}

await promises.mkdir(argv.tempDirectory, { recursive: true })
Expand Down
20 changes: 20 additions & 0 deletions lib/rmrf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = function (dir, cb, platform) {
/*
* this function will async 'rm -rf' <dir> using platform's native rm/rd command
*/
// win32
if ((platform || process.platform) === 'win32') {
require('child_process').spawn((
'rd /s /q ' + JSON.stringify(require('path').normalize(dir))
), {
// in win32, 'rd' is bultin-shell-command that cannot run outside shell
shell: true,
stdio: 'ignore'
}).on('error', cb).on('exit', cb.bind(undefined, undefined))
return
}
// posix
require('child_process').spawn('rm', ['-rf', dir], {
stdio: 'ignore'
}).on('error', cb).on('exit', cb.bind(undefined, undefined))
}
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-report": "^3.0.0",
"istanbul-reports": "^3.0.2",
"rimraf": "^3.0.0",
"test-exclude": "^6.0.0",
"v8-to-istanbul": "^7.0.0",
"yargs": "^16.0.0",
Expand Down
6 changes: 3 additions & 3 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const c8Path = require.resolve('../bin/c8')
const nodePath = process.execPath
const tsNodePath = './node_modules/.bin/ts-node'
const chaiJestSnapshot = require('chai-jest-snapshot')
const rimraf = require('rimraf')
const rmrf = require('../lib/rmrf')

require('chai')
.use(chaiJestSnapshot)
.should()

before(cb => rimraf('tmp', cb))
before(cb => rmrf('tmp', cb))

const nodeMajorVersion = Number(process.version.slice(1).split('.')[0])
beforeEach(function () {
Expand Down Expand Up @@ -295,7 +295,7 @@ describe('c8', () => {
})

describe('source-maps', () => {
beforeEach(cb => rimraf('tmp/source-map', cb))
beforeEach(cb => rmrf('tmp/source-map', cb))

describe('TypeScript', () => {
// Bugs:
Expand Down
40 changes: 23 additions & 17 deletions test/integration.js_10.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ covered
--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 76.18 | 61.18 | 68.57 | 76.18 |
All files | 74.14 | 61.63 | 66.67 | 74.14 |
bin | 78.85 | 60 | 66.67 | 78.85 |
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
lib | 80.67 | 52.73 | 84.21 | 80.67 |
lib | 77.62 | 53.57 | 80 | 77.62 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 60 | 84.62 | 75.17 | ...206,237-238,264-265,271-273
rmrf.js | 5 | 100 | 0 | 5 | 2-20
source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23
lib/commands | 44.44 | 75 | 16.67 | 44.44 |
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
Expand Down Expand Up @@ -140,13 +141,14 @@ hey
--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 75.69 | 58.75 | 67.65 | 75.69 |
All files | 73.59 | 59.26 | 65.71 | 73.59 |
bin | 78.85 | 60 | 66.67 | 78.85 |
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
lib | 80.67 | 52.73 | 84.21 | 80.67 |
lib | 77.62 | 53.57 | 80 | 77.62 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 60 | 84.62 | 75.17 | ...206,237-238,264-265,271-273
rmrf.js | 5 | 100 | 0 | 5 | 2-20
source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23
lib/commands | 44.44 | 75 | 16.67 | 44.44 |
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
Expand All @@ -155,9 +157,9 @@ All files | 75.69 | 58.75 | 67.65 | 75.69 |
async.js | 100 | 100 | 100 | 100 |
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
,ERROR: Coverage for lines (75.69%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.75%) does not meet global threshold (82%)
ERROR: Coverage for statements (75.69%) does not meet global threshold (95%)
,ERROR: Coverage for lines (73.59%) does not meet global threshold (101%)
ERROR: Coverage for branches (59.26%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.59%) does not meet global threshold (95%)
"
`;

Expand All @@ -178,6 +180,8 @@ ERROR: Coverage for branches (45.45%) does not meet threshold (82%) for lib/pars
ERROR: Coverage for lines (75.17%) does not meet threshold (101%) for lib/report.js
ERROR: Coverage for branches (60%) does not meet threshold (82%) for lib/report.js
ERROR: Coverage for statements (75.17%) does not meet threshold (95%) for lib/report.js
ERROR: Coverage for lines (5%) does not meet threshold (101%) for lib/rmrf.js
ERROR: Coverage for statements (5%) does not meet threshold (95%) for lib/rmrf.js
ERROR: Coverage for lines (44%) does not meet threshold (101%) for lib/source-map-from-file.js
ERROR: Coverage for statements (44%) does not meet threshold (95%) for lib/source-map-from-file.js
ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js
Expand All @@ -190,9 +194,9 @@ ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixt
exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`;

exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
",,ERROR: Coverage for lines (75.69%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.75%) does not meet global threshold (82%)
ERROR: Coverage for statements (75.69%) does not meet global threshold (95%)
",,ERROR: Coverage for lines (73.59%) does not meet global threshold (101%)
ERROR: Coverage for branches (59.26%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.59%) does not meet global threshold (95%)
"
`;

Expand Down Expand Up @@ -275,13 +279,14 @@ exports[`c8 report generates report from existing temporary files 1`] = `
",--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 75.69 | 58.75 | 67.65 | 75.69 |
All files | 73.59 | 59.26 | 65.71 | 73.59 |
bin | 78.85 | 60 | 66.67 | 78.85 |
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
lib | 80.67 | 52.73 | 84.21 | 80.67 |
lib | 77.62 | 53.57 | 80 | 77.62 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 60 | 84.62 | 75.17 | ...206,237-238,264-265,271-273
rmrf.js | 5 | 100 | 0 | 5 | 2-20
source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23
lib/commands | 44.44 | 75 | 16.67 | 44.44 |
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
Expand All @@ -297,13 +302,14 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = `
",--------------------------|---------|----------|---------|---------|--------------------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
--------------------------|---------|----------|---------|---------|--------------------------------
All files | 75.69 | 58.75 | 67.65 | 75.69 |
All files | 73.59 | 59.26 | 65.71 | 73.59 |
bin | 78.85 | 60 | 66.67 | 78.85 |
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
lib | 80.67 | 52.73 | 84.21 | 80.67 |
lib | 77.62 | 53.57 | 80 | 77.62 |
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
parse-args.js | 96.13 | 45.45 | 100 | 96.13 | 109-110,118-119,132-133
report.js | 75.17 | 60 | 84.62 | 75.17 | ...206,237-238,264-265,271-273
rmrf.js | 5 | 100 | 0 | 5 | 2-20
source-map-from-file.js | 44 | 100 | 0 | 44 | 10-23
lib/commands | 44.44 | 75 | 16.67 | 44.44 |
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
Expand All @@ -312,9 +318,9 @@ All files | 75.69 | 58.75 | 67.65 | 75.69 |
async.js | 100 | 100 | 100 | 100 |
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
--------------------------|---------|----------|---------|---------|--------------------------------
,ERROR: Coverage for lines (75.69%) does not meet global threshold (101%)
ERROR: Coverage for branches (58.75%) does not meet global threshold (82%)
ERROR: Coverage for statements (75.69%) does not meet global threshold (95%)
,ERROR: Coverage for lines (73.59%) does not meet global threshold (101%)
ERROR: Coverage for branches (59.26%) does not meet global threshold (82%)
ERROR: Coverage for statements (73.59%) does not meet global threshold (95%)
"
`;
Expand Down
15 changes: 15 additions & 0 deletions test/rmrf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* global describe, it */

const rmrf = require('../lib/rmrf')

describe('rmrf', () => {
/*
* dummy test to mock rmrf in win32 and posix for code-coverage-completion
*/
it('rmrf in win32', (done) => {
rmrf('undefined', done.bind(undefined, undefined), 'win32')
})
it('rmrf in posix', (done) => {
rmrf('undefined', done.bind(undefined, undefined), 'linux')
})
})

0 comments on commit 47daa99

Please sign in to comment.