Skip to content

Commit

Permalink
refactor: use fs-extra.copy/copySync
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Dec 26, 2021
1 parent 8461d20 commit 1896ce4
Show file tree
Hide file tree
Showing 3 changed files with 1,027 additions and 1,118 deletions.
13 changes: 7 additions & 6 deletions scripts/update-snapshots.js
@@ -1,7 +1,8 @@
#!/usr/bin/env node

const { readdirSync } = require('fs');
const { resolve, join } = require('path');
const { readdirSync, copydirSync, copyFileSync, rimrafSync } = require('sander');
const { copySync, removeSync } = require('fs-extra');

const basePath = resolve(__dirname, '../test');

Expand All @@ -14,10 +15,10 @@ for (const dir of formDirsToHandle) {
formDirsToHandle.push(...testFiles.map(filename => join(dir, filename)));
} else if (testFiles.includes('_actual')) {
const expectedPath = join(testPath, '_expected');
rimrafSync(expectedPath);
copydirSync(join(testPath, '_actual')).to(expectedPath);
removeSync(expectedPath);
copySync(join(testPath, '_actual'), expectedPath);
} else if (testFiles.includes('_actual.js')) {
copyFileSync(join(testPath, '_actual.js')).to(join(testPath, '_expected.js'));
copySync(join(testPath, '_actual.js'), join(testPath, '_expected.js'));
} else {
throw new Error(`Could not find test output in ${testPath}`);
}
Expand All @@ -32,8 +33,8 @@ for (const dir of chunkingDirsToHandle) {
chunkingDirsToHandle.push(...testFiles.map(filename => join(dir, filename)));
} else if (testFiles.includes('_actual')) {
const expectedPath = join(testPath, '_expected');
rimrafSync(expectedPath);
copydirSync(join(testPath, '_actual')).to(expectedPath);
removeSync(expectedPath);
copySync(join(testPath, '_actual'), expectedPath);
} else {
throw new Error(`Could not find test output in ${testPath}`);
}
Expand Down
17 changes: 9 additions & 8 deletions test/cli/index.js
@@ -1,8 +1,9 @@
const assert = require('assert');
const { exec } = require('child_process');
const { existsSync, readFileSync } = require('fs');
const path = require('path');
const sander = require('sander');
const { basename, resolve, sep } = require('path');
const process = require('process');
const { copySync, removeSync, statSync } = require('fs-extra');
const {
normaliseOutput,
runTestSuiteWithSamples,
Expand All @@ -11,22 +12,22 @@ const {

const cwd = process.cwd();

sander.rimrafSync(__dirname, 'node_modules');
sander.copydirSync(__dirname, 'node_modules_rename_me').to(__dirname, 'node_modules');
removeSync(resolve(__dirname, 'node_modules'));
copySync(resolve(__dirname, 'node_modules_rename_me'), resolve(__dirname, 'node_modules'));

runTestSuiteWithSamples(
'cli',
path.resolve(__dirname, 'samples'),
resolve(__dirname, 'samples'),
(dir, config) => {
(config.skip ? it.skip : config.solo ? it.only : it)(
path.basename(dir) + ': ' + config.description,
basename(dir) + ': ' + config.description,
done => {
process.chdir(config.cwd || dir);
if (config.before) config.before();

const command = config.command.replace(
/(^| )rollup($| )/g,
`node ${path.resolve(__dirname, '../../dist/bin')}${path.sep}rollup `
`node ${resolve(__dirname, '../../dist/bin')}${sep}rollup `
);

const childProcess = exec(
Expand Down Expand Up @@ -99,7 +100,7 @@ runTestSuiteWithSamples(
} catch (err) {
done(err);
}
} else if (existsSync('_expected') && sander.statSync('_expected').isDirectory()) {
} else if (existsSync('_expected') && statSync('_expected').isDirectory()) {
try {
assertDirectoriesAreEqual('_actual', '_expected');
done();
Expand Down

0 comments on commit 1896ce4

Please sign in to comment.