diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4b8d00a..a020565 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -18,40 +18,6 @@ jobs: with: node-version: ${{ matrix.node-version }} - - name: Setup Testing Infra - run: | - cd test - npm install + - name: Run tests + run: node ./test/runTests.js - - name: "CommonJS Test" - run: | - cd test/cjs - npm run test - - - name: "ES Modules Test" - run: | - cd test/esm-node-native - npm run test - if: ${{ matrix.node-version == '14.x' }} - - - name: "Validate ES Modules == CommonJS" - run: | - cd test/validateModuleExportsMatchCommonJS - npm run test - if: ${{ matrix.node-version == '14.x' }} - - - name: "Rollup Tree-shaking Test" - run: | - cd test/rollup-modules - npm run test - - - name: "Webpack Tree-shaking Test" - run: | - cd test/webpack-modules - npm run test - - - name: "Snowpack Tree-shaking Test" - run: | - cd test/snowpack-modules - npm run test - if: ${{ matrix.node-version == '14.x' }} diff --git a/test/esm-node-native/package.json b/test/esm-node-native/package.json index 166e509..5f9ee8c 100644 --- a/test/esm-node-native/package.json +++ b/test/esm-node-native/package.json @@ -2,5 +2,8 @@ "type": "module", "scripts": { "test": "node index.js" + }, + "engines": { + "node": "14" } } diff --git a/test/runTests.js b/test/runTests.js new file mode 100644 index 0000000..51090c1 --- /dev/null +++ b/test/runTests.js @@ -0,0 +1,54 @@ +const { spawnSync } = require("child_process"); +const fs = require("fs"); +const path = require("path"); +const mainVersion = Number(process.version.replace("v","").split(".")[0]) + +// Loop through all the folders and run `npm test` + +const blocklist = ["validateModuleExportsMatchCommonJS", "node_modules"]; +const filesInTest = fs.readdirSync(__dirname); +const tests = filesInTest + .filter((f) => fs.statSync(path.join(__dirname, f)).isDirectory()) + .filter((f) => !blocklist.includes(f)); + +// Support setting up the test node modules +if (!filesInTest.includes("node_modules")) { + console.log("Installing Deps..."); + spawnSync("npm", ["install"], { cwd: __dirname }); + console.log("Installed"); +} + +const chalk = require("chalk").default; +for (const test of tests) { + console.log("---> " + chalk.bold(test)); + + const pgkJSON = require(path.join(__dirname, test, "package.json")); + + // Allow skipping things which need a minimum of node 14 (es modules) + if (pgkJSON.engines && pgkJSON.engines.node) { + const minVersion = Number(pgkJSON.engines.node) + if (minVersion > mainVersion) { + console.log("Skipping") + continue + } + } + + // The webpack 5 tests have unique deps + if (pgkJSON.dependencies || pgkJSON.devDependencies) { + const nodeModsInstalled = fs.existsSync(path.join(__dirname, test, "node_modules")); + if (!nodeModsInstalled) { + spawnSync("npm", ["install"], { cwd: path.join(__dirname, test) }); + } + } + + // Run the test command + const results = spawnSync("npm", ["test"], { cwd: path.join(__dirname, test) }); + console.log(results.stdout.toString()) + if (results.status) { + console.log(chalk.bold.red("Error running test: ") + chalk.bold(test)) + console.log(results.stderr.toString()) + console.log(chalk.bold.red("^^^ Error running test: ") + chalk.bold(test)) + process.exitCode = results.status + } +} + diff --git a/test/snowpack-modules/package.json b/test/snowpack-modules/package.json index 2936b57..ca7826b 100644 --- a/test/snowpack-modules/package.json +++ b/test/snowpack-modules/package.json @@ -3,5 +3,8 @@ "scripts": { "test": "../node_modules/.bin/snowpack build; node build/index.js" + }, + "engines": { + "node": "14" } } diff --git a/test/webpack-modules/index.js b/test/webpack-4-modules/index.js similarity index 100% rename from test/webpack-modules/index.js rename to test/webpack-4-modules/index.js diff --git a/test/webpack-modules/package.json b/test/webpack-4-modules/package.json similarity index 100% rename from test/webpack-modules/package.json rename to test/webpack-4-modules/package.json diff --git a/test/webpack-modules/webpack.config.js b/test/webpack-4-modules/webpack.config.js similarity index 100% rename from test/webpack-modules/webpack.config.js rename to test/webpack-4-modules/webpack.config.js diff --git a/test/webpack-5-modules/index.js b/test/webpack-5-modules/index.js new file mode 100644 index 0000000..a147352 --- /dev/null +++ b/test/webpack-5-modules/index.js @@ -0,0 +1,2 @@ +import { __awaiter } from "tslib"; +if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter"); diff --git a/test/webpack-5-modules/package.json b/test/webpack-5-modules/package.json new file mode 100644 index 0000000..e634d9a --- /dev/null +++ b/test/webpack-5-modules/package.json @@ -0,0 +1,10 @@ +{ + "scripts": { + "test": "webpack && node build/main.js" + }, + "devDependencies": { + "tslib": "file:../..", + "webpack": "5.0.0-rc.4", + "webpack-cli": "3.3.12" + } +} diff --git a/test/webpack-5-modules/webpack.config.js b/test/webpack-5-modules/webpack.config.js new file mode 100644 index 0000000..47956e1 --- /dev/null +++ b/test/webpack-5-modules/webpack.config.js @@ -0,0 +1,12 @@ +const path = require('path'); + +/** @type {import("webpack").Configuration} */ +const config = { + mode: "production", + entry: "./index", + output: { + path: path.join(process.cwd(), 'build') + } +} + +module.exports = config