Skip to content

Commit dbba970

Browse files
committed
Add test for Node ESM conditional exports
1 parent 0f20aa2 commit dbba970

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

.github/workflows/test.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10+
# Change the condition for ESM Dist Test below when changing this.
1011
node-version: [10.x, 12.x, 14.x]
1112
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Use Node.js ${{ matrix.node-version }}
15-
uses: actions/setup-node@v1
16-
with:
17-
node-version: ${{ matrix.node-version }}
18-
- name: Install
19-
run: npm install
20-
- name: Build and Test
21-
run: npm test
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Use Node.js ${{ matrix.node-version }}
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node-version }}
19+
- name: Install
20+
run: npm install
21+
- name: Build and Test
22+
run: npm test
23+
- if: matrix.node-version == '14.x'
24+
name: ESM Dist Test
25+
run: npm run test:dist

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package-lock.json
55
dist
66
mini
77
yarn.lock
8+
htm.tgz

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@
4848
"build:babel": "cd packages/babel-plugin-htm && npm run build",
4949
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-htm && npm run build",
5050
"build:mjsalias": "cp dist/htm.module.js dist/htm.mjs && cp mini/index.module.js mini/index.mjs && cp preact/index.module.js preact/index.mjs && cp preact/standalone.module.js preact/standalone.mjs && cp react/index.module.js react/index.mjs",
51-
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
51+
"test": "eslint src/**/*.mjs test/**/*.mjs --ignore-path .gitignore && npm run build && jest test",
5252
"test:perf": "v8 test/__perftest.mjs",
53+
"test:dist": "npm pack && mv htm*.tgz test/fixtures/esm/htm.tgz && cd test/fixtures/esm && npm install && node index.js",
5354
"release": "npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
5455
},
5556
"files": [

test/fixtures/esm/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "htm";
2+
import "htm/preact";
3+
import "htm/preact/standalone";
4+
// TODOD: Enable once react distro is ESM compatible.
5+
// import "htm/react";

test/fixtures/esm/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "htm_dist_test",
3+
"type": "module",
4+
"private": true,
5+
"description": "A package to test importing htm as ES modules in Node",
6+
"dependencies": {
7+
"htm": "file:htm.tgz",
8+
"preact": "^10.4.1"
9+
}
10+
}

0 commit comments

Comments
 (0)