Skip to content

Commit

Permalink
tests: use matrix for env tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 28, 2023
1 parent fd96d14 commit 795d064
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 4 deletions.
16 changes: 12 additions & 4 deletions .github/workflows/test-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions testcases/test-env/test-tsc/js-commonjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { ethers } = require("ethers");

console.log("Version:", ethers.version);

console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));
5 changes: 5 additions & 0 deletions testcases/test-env/test-tsc/js-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ethers } from "ethers";

console.log("Version:", ethers.version);

console.log(ethers.getAddress("0x0123456789abcdef0123456789abcdef01234567"));
30 changes: 30 additions & 0 deletions testcases/test-env/test-tsc/package.json
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions testcases/test-env/test-tsc/prepare.cjs
Original file line number Diff line number Diff line change
@@ -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 changes: 19 additions & 0 deletions testcases/test-env/test-tsc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
],
}

0 comments on commit 795d064

Please sign in to comment.