Skip to content

Commit

Permalink
[micropack] Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smialy committed Feb 23, 2024
1 parent 294393a commit 497c491
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/micropack/src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ program
'Files .css will be parsed as modules (default: null)',
DEFAULT_OPTIONS.cssModule
)
.option('--timestamp', 'Add timestamp to beging of file', false)
.option('--no-timestamp', 'Add timestamp to beging of file', true)
.action(async (opts) => {
console.log(opts)
try {
await micropack(opts);
} catch (e) {
Expand All @@ -69,7 +70,7 @@ program.on('--help', function () {

export function run(argv) {
setupExceptionHandler();
console.log(argv)
program.parse(argv);
}

run(process.argv);
4 changes: 3 additions & 1 deletion packages/micropack/src/utils/cmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export const collectDict = (vals, acc) => ({
return acc;
}, {}),
});
export const collectList = (vals, acc) => [...acc, ...vals.split(',')];
export const collectList = (vals, acc=[]) => {
return [...acc, ...vals.split(',')];
}
export const increaseVerbose = (_, acc) => (acc += 1);
1 change: 1 addition & 0 deletions packages/micropack/test/__snapshots__/index.test.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ css-module
index.mjs
package.json
src
declarations.d.ts
index.ts
main.css
main.module.css
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module '*.css';
3 changes: 1 addition & 2 deletions packages/micropack/test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { buildFixture, printDirTree, findAllFiles } from './utils.mjs';

chai.use(jestSnapshotPlugin());


const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

const FIXTURES_DIR = `${__dirname}fixtures`;
Expand Down Expand Up @@ -41,6 +40,6 @@ describe('fixtures', () => {
for(const [name, filePath] of files) {
expect(readFileSync(filePath, { encoding: 'utf8'})).toMatchSnapshot(`dist/${name}`);
}
});
}).timeout(5000);
});
});
Empty file removed packages/micropack/test/setup.mjs
Empty file.
11 changes: 10 additions & 1 deletion packages/micropack/test/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import {readFileSync} from 'fs';
import Path from 'node:path';
import Url from 'node:url';
import {execaSync} from 'execa';
import dirTree from 'directory-tree';


const __dirname = Url.fileURLToPath(new URL('.', import.meta.url));
const mainScript = Path.resolve(__dirname, '../src/cli.mjs');

export function buildFixture(path) {
const build = JSON.parse(readFileSync(Path.join(path, 'package.json')))['scripts']['build'];
const buildParams = build.split(' ').slice(1);
const params = [mainScript, ...buildParams, '--no-timestamp'];
try {
const result = execaSync('npm', ['run', 'build'], {cwd: path});
const result = execaSync('node', params, {cwd: path});
if (result.stderr) {
return result.stderr;
}
Expand Down

0 comments on commit 497c491

Please sign in to comment.