Skip to content

Commit

Permalink
refactor: use fs.unlinkSync
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 26, 2021
1 parent a844998 commit 6b0a7b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
6 changes: 3 additions & 3 deletions test/cli/samples/warn-broken-sourcemap/_config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const fs = require('fs');
const { unlinkSync } = require('fs');
const path = require('path');
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'displays warnings for broken sourcemaps',
command: 'rollup -c',
stderr: stderr => {
fs.unlinkSync(path.resolve(__dirname, 'bundle'));
fs.unlinkSync(path.resolve(__dirname, 'bundle.map'));
unlinkSync(path.resolve(__dirname, 'bundle'));
unlinkSync(path.resolve(__dirname, 'bundle.map'));
assertIncludes(
stderr,
'(!) Broken sourcemap\n' +
Expand Down
6 changes: 3 additions & 3 deletions test/cli/samples/warn-broken-sourcemaps/_config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const fs = require('fs');
const { unlinkSync } = require('fs');
const path = require('path');
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'displays warnings for broken sourcemaps',
command: 'rollup -c',
stderr: stderr => {
fs.unlinkSync(path.resolve(__dirname, 'bundle'));
fs.unlinkSync(path.resolve(__dirname, 'bundle.map'));
unlinkSync(path.resolve(__dirname, 'bundle'));
unlinkSync(path.resolve(__dirname, 'bundle.map'));
assertIncludes(
stderr,
'(!) Broken sourcemap\n' +
Expand Down
3 changes: 2 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('assert');
const { unlinkSync } = require('fs');
const path = require('path');
const fixturify = require('fixturify');
const sander = require('sander');
Expand Down Expand Up @@ -151,7 +152,7 @@ function getFileNamesAndRemoveOutput(dir) {
return false;
}
if (fileName === '_actual.js') {
sander.unlinkSync(path.join(dir, '_actual.js'));
unlinkSync(path.join(dir, '_actual.js'));
return false;
}
return true;
Expand Down
22 changes: 11 additions & 11 deletions test/watch/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require('assert');
const { existsSync, readFileSync, writeFileSync } = require('fs');
const { existsSync, promises, readFileSync, unlinkSync, writeFileSync } = require('fs');
const path = require('path');
const sander = require('sander');
const rollup = require('../../dist/rollup');
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('rollup.watch', () => {
let ids;
const expectedIds = [WATCHED_ID, path.resolve('test/_tmp/input/main.js')];
await sander.copydir('test/watch/samples/watch-files').to('test/_tmp/input');
await sander.unlink(WATCHED_ID);
await promises.unlink(WATCHED_ID);
await wait(100);
watcher = rollup.watch({
input: 'test/_tmp/input/main.js',
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('rollup.watch', () => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
assert.deepStrictEqual(events, ['create', 'update']);
assert.deepStrictEqual(ids, expectedIds);
sander.unlinkSync(WATCHED_ID);
unlinkSync(WATCHED_ID);
},
'START',
'BUNDLE_START',
Expand Down Expand Up @@ -348,7 +348,7 @@ describe('rollup.watch', () => {
assert.strictEqual(lastEvent, null);
writeFileSync(WATCHED_ID, 'another');
await wait(100);
sander.unlinkSync(WATCHED_ID);
unlinkSync(WATCHED_ID);
},
'START',
'BUNDLE_START',
Expand All @@ -359,7 +359,7 @@ describe('rollup.watch', () => {
lastEvent = null;
writeFileSync(WATCHED_ID, '123');
await wait(100);
sander.unlinkSync(WATCHED_ID);
unlinkSync(WATCHED_ID);
// To ensure there is always another change to trigger a rebuild
writeFileSync(MAIN_ID, 'export default 43;');
},
Expand Down Expand Up @@ -648,14 +648,14 @@ describe('rollup.watch', () => {
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 42);
sander.unlinkSync('test/_tmp/input/main.js');
unlinkSync('test/_tmp/input/main.js');
writeFileSync('test/_tmp/input/main.js', 'export nope;');
},
'START',
'BUNDLE_START',
'ERROR',
() => {
sander.unlinkSync('test/_tmp/input/main.js');
unlinkSync('test/_tmp/input/main.js');
writeFileSync('test/_tmp/input/main.js', 'export default 43;');
},
'START',
Expand Down Expand Up @@ -690,14 +690,14 @@ describe('rollup.watch', () => {
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), 43);
sander.unlinkSync('test/_tmp/input/dep.js');
unlinkSync('test/_tmp/input/dep.js');
writeFileSync('test/_tmp/input/dep.js', 'export nope;');
},
'START',
'BUNDLE_START',
'ERROR',
() => {
sander.unlinkSync('test/_tmp/input/dep.js');
unlinkSync('test/_tmp/input/dep.js');
writeFileSync('test/_tmp/input/dep.js', 'export const value = 43;');
},
'START',
Expand Down Expand Up @@ -1670,7 +1670,7 @@ describe('rollup.watch', () => {
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), true);
sander.unlinkSync(WATCHED_ID);
unlinkSync(WATCHED_ID);
},
'START',
'BUNDLE_START',
Expand Down Expand Up @@ -1752,7 +1752,7 @@ describe('rollup.watch', () => {
'END',
() => {
assert.strictEqual(run('../_tmp/output/bundle.js'), true);
sander.unlinkSync('test/_tmp/input/dep');
unlinkSync('test/_tmp/input/dep');
},
'START',
'BUNDLE_START',
Expand Down

0 comments on commit 6b0a7b8

Please sign in to comment.