Skip to content

Commit dce1769

Browse files
committed
Refactor test cases into more granular files
1 parent 9717f2d commit dce1769

11 files changed

Lines changed: 151 additions & 127 deletions

File tree

.github/workflows/release-on-vtag.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
release:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v5 #see: https://github.com/actions/checkout/releases
14+
- uses: actions/checkout@v6 #see: https://github.com/actions/checkout/releases
1515
- uses: softprops/action-gh-release@v2 #see: https://github.com/softprops/action-gh-release/releases

.github/workflows/run-spec-on-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v5 #see: https://github.com/actions/checkout/releases
11+
- uses: actions/checkout@v6 #see: https://github.com/actions/checkout/releases
1212
- uses: actions/setup-node@v6 #see: https://github.com/actions/setup-node/releases
1313
- run: npm install
1414
- run: npm test

LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2025 Individual contributors to esm-to-plain-js
3+
Copyright (c) 2022-2026 Individual contributors to esm-to-plain-js
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@
5454
},
5555
"dependencies": {
5656
"chalk": "~5.6",
57-
"cli-argv-util": "~1.4",
57+
"cli-argv-util": "~1.5",
5858
"fancy-log": "~2.0",
5959
"slash": "~5.1"
6060
},
6161
"devDependencies": {
62-
"@eslint/js": "~9.39",
62+
"@eslint/js": "~10.0",
6363
"@types/fancy-log": "~2.0",
64-
"@types/node": "~25.0",
64+
"@types/node": "~25.3",
6565
"add-dist-header": "~1.6",
6666
"assert-deep-strict-equal": "~1.2",
6767
"copy-file-util": "~1.3",
68-
"eslint": "~9.39",
68+
"eslint": "~10.0",
6969
"jshint": "~2.13",
7070
"mocha": "~11.7",
7171
"rimraf": "~6.1",
7272
"run-scripts-util": "~1.3",
7373
"typescript": "~5.9",
74-
"typescript-eslint": "~8.50"
74+
"typescript-eslint": "~8.56"
7575
}
7676
}

spec/cli.spec.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// esm-to-plain-js
2+
// CLI Specification Suite
3+
4+
// Imports
5+
import { assertDeepStrictEqual, fileToLines } from 'assert-deep-strict-equal';
6+
import { cliArgvUtil } from 'cli-argv-util';
7+
import fs from 'fs';
8+
9+
// Setup
10+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
11+
const run = (posix) => cliArgvUtil.run(pkg, posix);
12+
13+
////////////////////////////////////////////////////////////////////////////////
14+
describe('Executing the CLI', () => {
15+
16+
it('comments out the imports and swaps the export for globalThis', () => {
17+
run('esm-to-plain-js --cd=spec/fixtures web-app.esm.js ../target/cli/web-app.cli.js');
18+
const actual = fileToLines('spec/target/cli/web-app.cli.js');
19+
const expected = [
20+
'// Ensure library is loaded => import * as R from \'ramda\';',
21+
'const webApp = {',
22+
' luckyNumbers: [3, 7, 21, 777],',
23+
' setup() {',
24+
' const elem = globalThis.document.getElementById(\'lucky-num\');',
25+
' elem.innerText = R.last(webApp.luckyNumbers);',
26+
' },',
27+
' };',
28+
'globalThis.webApp = webApp;',
29+
];
30+
assertDeepStrictEqual(actual, expected);
31+
});
32+
33+
});

spec/errors.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// esm-to-plain-js
2+
// Error Handling Specification Suite
3+
4+
// Imports
5+
import assert from 'assert';
6+
7+
// Setup
8+
import { esmToPlainJs } from '../dist/esm-to-plain-js.js';
9+
10+
////////////////////////////////////////////////////////////////////////////////
11+
describe('Correct error is thrown', () => {
12+
13+
it('when the "source" file parameter is missing', () => {
14+
const makeBogusCall = () => esmToPlainJs.transform();
15+
const exception = { message: '[esm-to-plain-js] Must specify a source file.' };
16+
assert.throws(makeBogusCall, exception);
17+
});
18+
19+
it('when the "target" file parameter is missing', () => {
20+
const source = 'spec/fixtures/web-app.esm.js';
21+
const makeBogusCall = () => esmToPlainJs.transform(source);
22+
const exception = { message: '[esm-to-plain-js] Must specify a target file.' };
23+
assert.throws(makeBogusCall, exception);
24+
});
25+
26+
});

spec/mocha.spec.js

Lines changed: 0 additions & 119 deletions
This file was deleted.

spec/package.spec.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// esm-to-plain-js
2+
// Package Specification Suite
3+
4+
// Imports
5+
import { assertDeepStrictEqual } from 'assert-deep-strict-equal';
6+
import fs from 'fs';
7+
8+
// Setup
9+
import { esmToPlainJs } from '../dist/esm-to-plain-js.js';
10+
11+
////////////////////////////////////////////////////////////////////////////////
12+
describe('The "dist" folder', () => {
13+
14+
it('contains the correct files', () => {
15+
const actual = fs.readdirSync('dist').sort();
16+
const expected = [
17+
'esm-to-plain-js.d.ts',
18+
'esm-to-plain-js.js',
19+
];
20+
assertDeepStrictEqual(actual, expected);
21+
});
22+
23+
});
24+
25+
////////////////////////////////////////////////////////////////////////////////
26+
describe('Library module', () => {
27+
28+
it('is an object', () => {
29+
const actual = { constructor: esmToPlainJs.constructor.name };
30+
const expected = { constructor: 'Object' };
31+
assertDeepStrictEqual(actual, expected);
32+
});
33+
34+
it('has functions named assert(), cli(), reporter(), and transform()', () => {
35+
const module = esmToPlainJs;
36+
const actual = Object.keys(module).sort().map(key => [key, typeof module[key]]);
37+
const expected = [
38+
['assert', 'function'],
39+
['cli', 'function'],
40+
['reporter', 'function'],
41+
['transform', 'function'],
42+
];
43+
assertDeepStrictEqual(actual, expected);
44+
});
45+
46+
});

0 commit comments

Comments
 (0)