8000 Tests: Move bundler code from npm scripts to a Node file · jquery/jquery@c8d1468 · GitHub
[go: up one dir, main page]

Skip to content

Commit c8d1468

Browse files
committed
Tests: Move bundler code from npm scripts to a Node file
1 parent edd36c6 commit c8d1468

File tree

9 files changed

+118
-35
lines changed

9 files changed

+118
-35
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
.sizecache.json
1010
yarn.lock
1111
.eslintcache
12+
tmp
1213

1314
npm-debug.log*
1415

@@ -29,7 +30,6 @@ npm-debug.log*
2930
/external
3031
/node_modules
3132

32-
/test/bundler_smoke_tests/tmp
3333
/test/data/core/jquery-iterability-transpiled.js
3434
/test/data/qunit-fixture.js
3535

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default [
1010
// See https://github.com/eslint/eslint/discussions/17412
1111
ignores: [
1212
"external",
13-
"test/bundler_smoke_tests/tmp",
13+
"**/tmp",
1414
"test/data/json_obj.js"
1515
]
1616
},

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
"pretest": "npm run qunit-fixture && npm run babel:tests && npm run npmcopy",
6060
"qunit-fixture": "node build/tasks/qunit-fixture.js",
6161
"start": "node -e \"require('./build/tasks/build.js').buildDefaultFiles({ watch: true })\"",
62-
"test:bundlers": "node -e \"require('./test/bundler_smoke_tests/utils.cjs').cleanTmpBundlersDir()\" && npm run build:all && rollup -c test/bundler_smoke_tests/rollup-pure-esm.config.js && rollup -c test/bundler_smoke_tests/rollup-commonjs.config.js && webpack -c test/bundler_smoke_tests/webpack.config.cjs && node test/bundler_smoke_tests/run-jsdom-tests.js",
62+
"test:bundlers": "npm run pretest && npm run build:all && test/bundler_smoke_tests/run-jsdom-tests.js",
6363
"test:browser": "npm run pretest && npm run build:main && npm run test:unit -- -b chrome -b firefox -h",
64-
"test:browserless": "npm run pretest && npm run test:bundlers && node build/tasks/node_smoke_tests.js && node build/tasks/promises_aplus_tests.js && npm run test:unit -- -b jsdom -m basic",
64+
"test:browserless": "npm run pretest && npm run build:all && test/bundler_smoke_tests/run-jsdom-tests.js && node build/tasks/node_smoke_tests.js && node build/tasks/promises_aplus_tests.js && npm run test:unit -- -b jsdom -m basic",
6565
"test:jsdom": "npm run pretest && npm run build:main && npm run test:unit -- -b jsdom -m basic",
6666
"test:node_smoke_tests": "npm run pretest && npm run build:all && node build/tasks/node_smoke_tests.js",
6767
"test:promises_aplus": "npm run build:main && node build/tasks/promises_aplus_tests.js",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { rollup } from "rollup";
2+
3+
import { loadConfigFile } from "rollup/loadConfigFile";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
8+
const pureEsmConfigPath = path.resolve(
9+
dirname, "..", "rollup-pure-esm.config.js" );
10+
const commonJSConfigPath = path.resolve(
11+
dirname, "..", "rollup-commonjs.config.js" );
12+
13+
async function runRollup( name, configPath ) {
14+
15+
console.log( `Running Rollup, version: ${ name }` );
16+
17+
// options is an array of "inputOptions" objects with an additional
18+
// "output" property that contains an array of "outputOptions".
19+
// We generate a single output so the array only has one element.
20+
const {
21+
options: [ optionsObj ],
22+
warnings
23+
} = await loadConfigFile( configPath, {} );
24+
25+
// "warnings" wraps the default `onwarn` handler passed by the CLI.
26+
// This prints all warnings up to this point:
27+
warnings.flush();
28+
29+
const bundle = await rollup( optionsObj );
30+
await Promise.all( optionsObj.output.map( bundle.write ) );
31+
32+
console.log( `Build completed: Rollup, version: ${ name }` );
33+
}
34+
35+
export async function runRollupPureEsm() {
36+
await runRollup( "pure ESM", pureEsmConfigPath );
37+
}
38+
39+
export async function runRollupEsmAndCommonJs() {
40+
await runRollup( "ESM + CommonJS", commonJSConfigPath );
41+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import webpack from "webpack";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
6+
const configPath = path.resolve( dirname, "..", "webpack.config.cjs" );
7+
8+
export async function runWebpack() {
9+
return new Promise( async( resolve, reject ) => {
10+
console.log( "Running Webpack" );
11+
12+
const { default: config } = await import( configPath );
13+
14+
webpack( config, ( err, stats ) => {
15+
if ( err || stats.hasErrors() ) {
16+
console.error( "Errors detected during Webpack compilation" );
17+
reject( err );
18+
return;
19 F438 +
}
20+
21+
console.log( "Build completed: Webpack" );
22+
resolve();
23+
} );
24+
} );
25+
}

test/bundler_smoke_tests/lib/utils.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
6+
const TMP_BUNDLERS_DIR = path.resolve( dirname, "..", "tmp" );
7+
8+
export async function cleanTmpBundlersDir() {
9+
await fs.rm( TMP_BUNDLERS_DIR, {
10+
force: true,
11+
recursive: true
12+
} );
13+
}

test/bundler_smoke_tests/run-jsdom-tests.js

100644100755
Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
#!/usr/bin/env node
2+
13
import fs from "node:fs/promises";
24
import jsdom, { JSDOM } from "jsdom";
35
import path from "node:path";
46
import { fileURLToPath } from "node:url";
7+
import { runRollupEsmAndCommonJs, runRollupPureEsm } from "./lib/run-rollup.js";
8+
import { runWebpack } from "./lib/run-webpack.js";
9+
import { cleanTmpBundlersDir } from "./lib/utils.js";
510

611
const dirname = path.dirname( fileURLToPath( import.meta.url ) );
712

813
async function runJSDOMTest( { title, folder } ) {
9-
console.log( "\nRunning bundlers tests:", title );
14+
console.log( "Running bundlers tests:", title );
1015

1116
const template = await fs.readFile( `${ dirname }/test.html`, "utf-8" );
1217
const scriptSource = await fs.readFile(
@@ -37,17 +42,34 @@ async function runJSDOMTest( { title, folder } ) {
3742
}
3843
}
3944

40-
await runJSDOMTest( {
41-
title: "Rollup with pure ESM setup",
42-
folder: "rollup-pure-esm"
43-
} );
45+
async function buildAndTest() {
46+
await cleanTmpBundlersDir();
47+
48+
await Promise.all( [
49+
runRollupPureEsm(),
50+
runRollupEsmAndCommonJs(),
51+
runWebpack()
52+
] );
53+
54+
await Promise.all( [
55+
runJSDOMTest( {
56+
title: "Rollup with pure ESM setup",
57+
folder: "rollup-pure-esm"
58+
} ),
4459

45-
await runJSDOMTest( {
46-
title: "Rollup with ESM + CommonJS",
47-
folder: "rollup-commonjs"
48-
} );
60+
runJSDOMTest( {
61+
title: "Rollup with ESM + CommonJS",
62+
folder: "rollup-commonjs"
63+
} ),
64+
65+
runJSDOMTest( {
66+
title: "Webpack",
67+
folder: "webpack"
68+
} )
69+
] );
70+
71+
// The directory won't be cleaned in case of failures; this may aid debugging.
72+
await cleanTmpBundlersDir();
73+
}
4974

50-
await runJSDOMTest( {
51-
title: "Webpack",
52-
folder: "webpack"
53-
} );
75+
await buildAndTest();

test/bundler_smoke_tests/utils.cjs

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

test/bundler_smoke_tests/webpack.config.cjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"use strict";
22

3-
const path = require( "path" );
4-
53
module.exports = {
64
entry: `${ __dirname }/src-esm-commonjs/main.js`,
75
output: {

0 commit comments

Comments
 (0)
0