Skip to content

Commit

Permalink
add bundle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Aug 15, 2023
1 parent 334a5d9 commit 74784f4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 9 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"scripts": {
"prepare": "npm run build",
"build": "rollup --config",
"test": "xo && ava && tsd"
"test": "xo && ava && tsd && npm run test:build",
"test:build": "npm run build && ava test/build.js"
},
"files": [
"build",
Expand Down Expand Up @@ -99,7 +100,8 @@
},
"ava": {
"files": [
"test/*"
"test/*",
"!test/build.js"
]
}
}
15 changes: 8 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import license from 'rollup-plugin-license';
import strip from 'strip-comments';
/// import strip from 'strip-comments';
import {defineConfig} from 'rollup';

const outputDirectory = 'build';
Expand All @@ -27,12 +27,13 @@ export default defineConfig({
return 'dependencies';
}
},
plugins: [{
name: 'strip-dependency-comments',
renderChunk(code, chunk) {
return chunk.name === 'dependencies' ? strip(code) : null;
},
}],
// TODO: strip deletes `https://...`
// plugins: [{
// name: 'strip-dependency-comments',
// renderChunk(code, chunk) {
// return chunk.name === 'dependencies' ? strip(code) : null;
// },
// }],
},
preserveEntrySignatures: 'allow-extension',
plugins: [
Expand Down
40 changes: 40 additions & 0 deletions test/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* eslint-disable ava/no-ignored-test-files */
import test from 'ava';
import {readPackage} from 'read-pkg';
import meow from '../build/index.js';
import {spawnFixture} from './_utils.js';

test('main', t => {
const cli = meow(`
Usage
foo <input>
`, {
importMeta: import.meta,
argv: 'foo --foo-bar --u cat -- unicorn cake'.split(' '),
flags: {
unicorn: {shortFlag: 'u'},
meow: {default: 'dog'},
'--': true,
},
});

t.like(cli, {
input: ['foo'],
flags: {
fooBar: true,
meow: 'dog',
unicorn: 'cat',
'--': ['unicorn', 'cake'],
},
pkg: {
name: 'meow',
},
help: '\n CLI app helper\n\n Usage\n foo <input>\n',
});
});

test('spawn cli and show version', async t => {
const pkg = await readPackage();
const {stdout} = await spawnFixture(['--version']);
t.is(stdout, pkg.version);
});
26 changes: 26 additions & 0 deletions test/fixtures/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env node
import process from 'node:process';
import meow from '../../build/index.js';

const cli = meow(`
Usage
foo <input>
`, {
importMeta: import.meta,
description: 'Custom description',
autoVersion: !process.argv.includes('--no-auto-version'),
autoHelp: !process.argv.includes('--no-auto-help'),
flags: {
unicorn: {shortFlag: 'u'},
meow: {default: 'dog'},
camelCaseOption: {default: 'foo'},
},
});

if (cli.flags.camelCaseOption === 'foo') {
for (const x of Object.keys(cli.flags)) {
console.log(x);
}
} else {
console.log(cli.flags.camelCaseOption);
}

0 comments on commit 74784f4

Please sign in to comment.