Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 2 additions & 36 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"sideEffects": false,
"exports": {
".": {
"module": "./tslib.es6.js",
"import": "./modules/index.js",
"default": "./tslib.js"
},
Expand Down
3 changes: 3 additions & 0 deletions test/esm-node-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
"type": "module",
"scripts": {
"test": "node index.js"
},
"engines": {
"node": "14"
}
}
54 changes: 54 additions & 0 deletions test/runTests.js
Original file line number Diff line number Diff line change
@@ -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
}
}

3 changes: 3 additions & 0 deletions test/snowpack-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@

"scripts": {
"test": "../node_modules/.bin/snowpack build; node build/index.js"
},
"engines": {
"node": "14"
}
}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions test/webpack-5-modules/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { __awaiter } from "tslib";
if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");
10 changes: 10 additions & 0 deletions test/webpack-5-modules/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
12 changes: 12 additions & 0 deletions test/webpack-5-modules/webpack.config.js
Original file line number Diff line number Diff line change
@@ -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