tests: use matrix for env tests
This commit is contained in:
parent
fd96d149ab
commit
795d064058
16
.github/workflows/test-env.yml
vendored
16
.github/workflows/test-env.yml
vendored
@ -18,7 +18,9 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
test: [ "ts-import-cjs-node16", "ts-import-esm-node16", "ts-import-cjs", "ts-import-esm", "test-3983" ]
|
||||
tsModuleResolution: [ "node", "node16", "nodenext" ]
|
||||
tsModule: [ "commonjs", "es2020" ]
|
||||
pkgType: [ "module", "commonjs" ]
|
||||
|
||||
steps:
|
||||
- name: Use Node.js
|
||||
@ -31,12 +33,18 @@ jobs:
|
||||
with:
|
||||
path: "faux_modules/ethers"
|
||||
|
||||
- name: Copy tests to working directory
|
||||
run: cp faux_modules/ethers/testcases/test-env/test-tsc/* .
|
||||
|
||||
- name: Prepare setup moduleResolution=${{ matrix.tsModuleResolution }} module=${{ matrix.tsModule }} type=${{ matrix.pkgType }}
|
||||
run: node preapre.cjs ${{ matrix.tsModuleResolution }} ${{ matrix.tsModule }} ${{ matrix.pkgType }}
|
||||
|
||||
- name: Dump Config
|
||||
run: cat package.json tsconfig.json
|
||||
|
||||
- name: Install and run Faux Registry
|
||||
uses: ethers-io/hijack-npm-action@main
|
||||
|
||||
- name: Copy tests to working directory
|
||||
run: cp faux_modules/ethers/testcases/test-env/${{ matrix.test }}/* .
|
||||
|
||||
- name: Install packages
|
||||
run: npm install
|
||||
|
||||
|
5
testcases/test-env/test-tsc/js-commonjs.js
Normal file
5
testcases/test-env/test-tsc/js-commonjs.js
Normal file
@ -0,0 +1,5 @@
|
||||
const { ethers } = require("ethers");
|
||||
|
||||
console.log("Version:", ethers.version);
|
||||
|
||||
console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));
|
5
testcases/test-env/test-tsc/js-module.js
Normal file
5
testcases/test-env/test-tsc/js-module.js
Normal file
@ -0,0 +1,5 @@
|
||||
import { ethers } from "ethers";
|
||||
|
||||
console.log("Version:", ethers.version);
|
||||
|
||||
console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));
|
30
testcases/test-env/test-tsc/package.json
Normal file
30
testcases/test-env/test-tsc/package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "test",
|
||||
"dependencies": {
|
||||
"ethers": "^6.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"version": "0.0.1",
|
||||
"description": "Test case for simple import for ethers.",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"publishConfig": {
|
||||
"access": "private"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc --project tsconfig.json",
|
||||
"clean": "rm -rf node_modules package-lock.json *.js *.d.ts",
|
||||
"postinstall": "find node_modules | grep package.json",
|
||||
"test": "npm run build && node index.js"
|
||||
},
|
||||
"keywords": [
|
||||
"ethers",
|
||||
"tests",
|
||||
"typescipt"
|
||||
],
|
||||
"type": "${PKG_TYPE}",
|
||||
"author": "Richard Moore <me@ricmoo.com>",
|
||||
"license": "MIT"
|
||||
}
|
19
testcases/test-env/test-tsc/prepare.cjs
Normal file
19
testcases/test-env/test-tsc/prepare.cjs
Normal file
@ -0,0 +1,19 @@
|
||||
const fs = require("fs");
|
||||
|
||||
function replace(filename, key, value) {
|
||||
const data = fs.readFileSync(filename).toString();
|
||||
data = data.replace(key, value);
|
||||
fs.writeFileSync(filename, data);
|
||||
}
|
||||
|
||||
// moduleResolution: node, node16, nodenext
|
||||
replace("tsconfig.json", "${TS_MODULE_RESOLUTION}", process.argv[2]);
|
||||
|
||||
// module: commonjs, es2020
|
||||
replace("tsconfig.json", "${TS_MODULE}", process.argv[3]);
|
||||
|
||||
// type: module, commonjs
|
||||
replace("package.json", "${PKG_TYPE}", process.argv[4]);
|
||||
|
||||
// JavaScript
|
||||
fs.writeFileSync("index.js", fs.readFileSync("js-" + process.argv[4] + ".js"));
|
19
testcases/test-env/test-tsc/tsconfig.json
Normal file
19
testcases/test-env/test-tsc/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"importHelpers": false,
|
||||
"lib": [
|
||||
"dom",
|
||||
"es2020",
|
||||
"es5"
|
||||
],
|
||||
"module": "${TS_MODULE}",
|
||||
"moduleResolution": "${TS_MODULE_RESOLUTION}",
|
||||
"strict": true,
|
||||
"target": "es2022"
|
||||
},
|
||||
"exclude": [ ],
|
||||
"include": [
|
||||
"./index.ts"
|
||||
],
|
||||
}
|
Loading…
Reference in New Issue
Block a user