Skip to content

Commit 7f84081

Browse files
committed
Move tests to mjs
1 parent 8a4e977 commit 7f84081

File tree

5 files changed

+12
-18
lines changed

5 files changed

+12
-18
lines changed

package.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
"umd:main": "dist/htm.umd.js",
77
"module": "dist/htm.mjs",
88
"scripts": {
9-
"build": "npm run build:main && npm run build:preact && npm run build:babel",
9+
"build": "npm run -s build:main && npm run -s build:preact && npm run -s build:babel",
1010
"build:main": "microbundle src/index.mjs -f es,umd --no-sourcemap --target web && microbundle src/cjs.mjs -f iife --no-sourcemap --target web",
1111
"build:preact": "cd src/integrations/preact && npm run build",
1212
"build:babel": "cd packages/babel-plugin-htm && npm run build",
13-
"test": "eslint src/**/*.mjs test && npm run build && jest test",
13+
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
1414
"release": "npm run build && git checkout --detach && git add -f babel dist preact && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push --tags && git checkout master"
1515
},
1616
"files": [
@@ -32,17 +32,16 @@
3232
"**/?(*.)(spec|test).?(m)js?(x)"
3333
],
3434
"transform": {
35-
"\\.mjs$": "babel-jest"
35+
"\\.m?js$": "babel-jest"
3636
},
3737
"moduleFileExtensions": [
3838
"mjs",
3939
"js"
4040
],
4141
"moduleNameMapper": {
42-
"^htm-babel-plugin$": "<rootDir>/packages/babel-plugin-htm/dist/babel-plugin-htm.js",
43-
"^babel-plugin-htm$": "<rootDir>/packages/babel-plugin-htm/dist/babel-plugin-htm.js",
44-
"^htm$": "<rootDir>/dist/htm.js",
45-
"^htm/preact$": "<rootDir>/preact/index.js"
42+
"^babel-plugin-htm$": "<rootDir>/packages/babel-plugin-htm/index.mjs",
43+
"^htm$": "<rootDir>/src/index.mjs",
44+
"^htm/preact$": "<rootDir>/src/integrations/preact/index.mjs"
4645
}
4746
},
4847
"babel": {

packages/babel-plugin-htm/index.mjs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import { JSDOM } from 'jsdom';
2-
const before = global.document;
3-
global.document = new JSDOM().window.document;
4-
const htm = require('htm');
5-
global.document = before;
1+
import htm from 'htm';
62

73
// htm() uses the HTML parser, which serializes attribute values.
84
// this is a problem, because composite values here can be made up

packages/babel-plugin-htm/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
"license": "Apache-2.0",
3030
"homepage": "https://github.com/developit/htm/tree/master/packages/babel-plugin-htm",
3131
"dependencies": {
32-
"htm": "^1.0.0",
33-
"jsdom": "^11.12.0"
32+
"htm": "^1.0.0"
3433
},
3534
"devDependencies": {
3635
"microbundle": "^0.6.0"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @jest-environment node
33
*/
44

5-
const { transform } = require('@babel/core');
6-
const htmBabelPlugin = require('babel-plugin-htm');
5+
import { transform } from '@babel/core';
6+
import htmBabelPlugin from 'babel-plugin-htm';
77

88
describe('htm/babel', () => {
99
test('basic transformation', () => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* limitations under the License.
1212
*/
1313

14-
const { html, Component, render } = require('htm/preact');
14+
import { html, Component, render } from 'htm/preact';
1515

1616
describe('htm/preact', () => {
1717
const scratch = document.createElement('div');
@@ -45,7 +45,7 @@ describe('htm/preact', () => {
4545

4646
const Baz = ({ myCaseSensitiveProp }) => html`<div>${myCaseSensitiveProp}</div>`;
4747

48-
const fullHtml = '<div class="foo">\n\t\t\t\t\t<h1>Name: jason</h1>\n\t\t\t\t\t<p>Hello world!</p>\n\t\t\t\t\t<button>Click Me</button>\n\t\t\t\t\t<pre>Count: 0</pre>\n\t\t\t\t\txml-style end tags:\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\t\n\t</div>\n\t\t\t\t\texplicit end tags:\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\tsome children (count=0)\n\t</div>\n\t\t\t\t\timplicit end tags: (&lt;//&gt;)\n\t\t\t\t\t<div>\n\t\tValue of hello: true\n\t\tsome children (count=0)\n\t</div>\n\t\t\t\t\tsome text at the end\n\t\t\t\t</div>';
48+
const fullHtml = '<div class="foo"><h1>Name: jason</h1><p>Hello world!</p><button>Click Me</button><pre>Count: 0</pre>xml-style end tags:<div>Value of hello: true</div>explicit end tags:<div>Value of hello: truesome children (count=0)</div>implicit end tags: (&lt;//&gt;)<div>Value of hello: truesome children (count=0)</div>some text at the end</div>';
4949

5050
test('initial render', () => {
5151
render(html`<${Foo} name=jason />`, scratch);

0 commit comments

Comments
 (0)