tests: use matrix for env tests

This commit is contained in:
Richard Moore 2023-04-28 20:11:35 +09:00
parent fd96d149ab
commit 795d064058
6 changed files with 90 additions and 4 deletions

View File

@ -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

View File

@ -0,0 +1,5 @@
const { ethers } = require("ethers");
console.log("Version:", ethers.version);
console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));

View File

@ -0,0 +1,5 @@
import { ethers } from "ethers";
console.log("Version:", ethers.version);
console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));

View 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"
}

View 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"));

View 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"
],
}