Skip to content

Commit 366f6ac

Browse files
committed
Update to Jest 24, move the JSX transform tests to ./test
1 parent 6e543e3 commit 366f6ac

File tree

5 files changed

+57
-80
lines changed

5 files changed

+57
-80
lines changed

babel.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
'@babel/preset-env',
5+
{
6+
targets: {
7+
node: 'current'
8+
}
9+
}
10+
]
11+
]
12+
};

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
"umd:main": "dist/htm.umd.js",
77
"module": "dist/htm.mjs",
88
"scripts": {
9-
"build": "npm run -s build:main && npm run -s build:preact && npm run -s build:babel",
9+
"build": "npm run -s build:main && npm run -s build:preact && npm run -s build:babel && npm run -s build:babel-transform-jsx",
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+
"build:babel-transform-jsx": "cd packages/babel-plugin-transform-jsx-to-tagged-templates && npm run build",
1314
"test": "eslint src/**/*.mjs test/**/*.mjs && npm run build && jest test",
1415
"release": "npm t && git commit -am \"$npm_package_version\" && git tag $npm_package_version && git push && git push --tags && npm publish"
1516
},
@@ -39,16 +40,12 @@
3940
"js"
4041
],
4142
"moduleNameMapper": {
43+
"^babel-plugin-transform-jsx-to-tagged-templates$": "<rootDir>/packages/babel-plugin-transform-jsx-to-tagged-templates/src/index.mjs",
4244
"^babel-plugin-htm$": "<rootDir>/packages/babel-plugin-htm/index.mjs",
4345
"^htm$": "<rootDir>/src/index.mjs",
4446
"^htm/preact$": "<rootDir>/src/integrations/preact/index.mjs"
4547
}
4648
},
47-
"babel": {
48-
"presets": [
49-
"env"
50-
]
51-
},
5249
"repository": "developit/htm",
5350
"keywords": [
5451
"Hyperscript Tagged Markup",
@@ -66,11 +63,12 @@
6663
"devDependencies": {
6764
"@babel/core": "^7.2.2",
6865
"@babel/preset-env": "^7.1.6",
69-
"babel-jest": "^23.6.0",
66+
"babel-jest": "^24.1.0",
67+
"babel-plugin-jsx-pragmatic": "^1.0.2",
7068
"babel-preset-env": "^1.7.0",
7169
"eslint": "^5.2.0",
7270
"eslint-config-developit": "^1.1.1",
73-
"jest": "^23.4.2",
71+
"jest": "^24.1.0",
7472
"microbundle": "^0.8.3",
7573
"preact": "^8.4.2"
7674
},

packages/babel-plugin-transform-jsx-to-tagged-templates/package.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,12 @@
66
"module": "dist/babel-plugin-transform-jsx-to-tagged-templates.mjs",
77
"scripts": {
88
"build": "microbundle src/index.mjs -f es,cjs --target node --no-compress --no-sourcemap",
9-
"test": "jest",
109
"prepare": "npm run build"
1110
},
1211
"files": [
1312
"dist",
1413
"src"
1514
],
16-
"eslintConfig": {
17-
"extends": "developit"
18-
},
19-
"babel": {
20-
"presets": [
21-
"@babel/preset-env"
22-
]
23-
},
24-
"jest": {
25-
"moduleFileExtensions": [
26-
"mjs",
27-
"js",
28-
"json"
29-
],
30-
"transform": {
31-
"^.+\\.m?js$": "babel-jest"
32-
}
33-
},
3415
"repository": "developit/htm",
3516
"keywords": [
3617
"tagged template",
@@ -48,17 +29,6 @@
4829
"license": "Apache-2.0",
4930
"homepage": "https://github.com/developit/htm/tree/master/packages/babel-plugin-transform-jsx-to-tagged-templates",
5031
"devDependencies": {
51-
"@babel/core": "^7.2.0",
52-
"@babel/preset-env": "^7.2.0",
53-
"babel-core": "^7.0.0-bridge.0",
54-
"babel-jest": "^23.6.0",
55-
"babel-plugin-jsx-pragmatic": "^1.0.2",
56-
"eslint": "^5.10.0",
57-
"eslint-config-developit": "^1.1.1",
58-
"jest": "^23.6.0",
5932
"microbundle": "^0.8.3"
60-
},
61-
"dependencies": {
62-
"@babel/plugin-syntax-jsx": "^7.2.0"
6333
}
6434
}

packages/babel-plugin-transform-jsx-to-tagged-templates/test/index.test.js renamed to test/babel-transform-jsx.test.mjs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { transform } from '@babel/core';
2-
import transformJsxToTaggedTemplatesPlugin from '../src/index.mjs';
2+
import transformJsxToTaggedTemplatesPlugin from 'babel-plugin-transform-jsx-to-tagged-templates';
33

44
function compile(code, { plugins = [], ...options } = {}) {
55
return transform(code, {
66
babelrc: false,
7+
configFile: false,
8+
sourceType: 'script',
79
plugins: [
810
...plugins,
911
[transformJsxToTaggedTemplatesPlugin, options]
@@ -32,7 +34,7 @@ describe('babel-plugin-transform-jsx-to-tagged-templates', () => {
3234
compile('(<Foo>a</Foo>);')
3335
).toBe('html`<${Foo}>a</${Foo}>`;');
3436
});
35-
37+
3638
test('static text', () => {
3739
expect(
3840
compile(`(<div>Hello</div>);`)
@@ -41,13 +43,13 @@ describe('babel-plugin-transform-jsx-to-tagged-templates', () => {
4143
compile(`(<div>こんにちわ</div>);`)
4244
).toBe('html`<div>こんにちわ</div>`;');
4345
});
44-
46+
4547
test('HTML entities get unescaped', () => {
4648
expect(
4749
compile(`(<div>&amp;</div>);`)
4850
).toBe('html`<div>&</div>`;');
4951
});
50-
52+
5153
test('&lt; gets wrapped into an expression container', () => {
5254
expect(
5355
compile(`(<div>a&lt;b&lt;&lt;&lt;c</div>);`)
@@ -80,31 +82,31 @@ describe('babel-plugin-transform-jsx-to-tagged-templates', () => {
8082
compile('(<div a="こんにちわ" />);')
8183
).toBe('html`<div a="こんにちわ"/>`;');
8284
});
83-
85+
8486
test('HTML entities get unescaped', () => {
8587
expect(
8688
compile(`(<div a="&amp;" />);`)
8789
).toBe('html`<div a="&"/>`;');
8890
});
89-
91+
9092
test('double quote values with single quotes', () => {
9193
expect(
9294
compile(`(<div a="'b'" />);`)
9395
).toBe(`html\`<div a="'b'"/>\`;`);
9496
});
95-
97+
9698
test('single quote values with double quotes', () => {
9799
expect(
98100
compile(`(<div a='"b"' />);`)
99101
).toBe(`html\`<div a='"b"'/>\`;`);
100102
});
101-
103+
102104
test('escape values with newlines as expressions', () => {
103105
expect(
104106
compile(`(<div a="\n" />);`)
105107
).toBe('html`<div a=${"\\n"}/>`;');
106108
});
107-
109+
108110
test('escape values with both single and double quotes as expressions', () => {
109111
expect(
110112
compile(`(<div a="&#34;'" />);`)
@@ -144,13 +146,13 @@ describe('babel-plugin-transform-jsx-to-tagged-templates', () => {
144146
compile('const Foo = props => <div a b> a \n <em> b \n B </em> c <strong> d </strong> e </div>;')
145147
).toBe('const Foo = props => html`<div a b> a<em> b B </em> c <strong> d </strong> e </div>`;');
146148
});
147-
149+
148150
test('nested JSX Expressions produce nested templates', () => {
149151
expect(
150152
compile('const Foo = props => <ul>{props.items.map(item =>\n <li>\n {item}\n </li>\n)}</ul>;')
151153
).toBe('const Foo = props => html`<ul>${props.items.map(item => html`<li>${item}</li>`)}</ul>`;');
152154
});
153-
155+
154156
test('empty expressions are ignored', () => {
155157
expect(
156158
compile(`(<div>{/* a comment */}</div>);`)

test/babel.test.mjs

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
import { transform } from '@babel/core';
66
import htmBabelPlugin from 'babel-plugin-htm';
77

8+
const options = {
9+
babelrc: false,
10+
configFile: false,
11+
sourceType: 'script',
12+
compact: true
13+
};
14+
815
describe('htm/babel', () => {
916
test('basic transformation', () => {
1017
expect(
1118
transform('html`<div id=hello>hello</div>`;', {
12-
babelrc: false,
13-
compact: true,
19+
...options,
1420
plugins: [
1521
htmBabelPlugin
1622
]
@@ -21,8 +27,7 @@ describe('htm/babel', () => {
2127
test('basic transformation with variable', () => {
2228
expect(
2329
transform('var name="world";html`<div id=hello>hello, ${name}</div>`;', {
24-
babelrc: false,
25-
compact: true,
30+
...options,
2631
plugins: [
2732
htmBabelPlugin
2833
]
@@ -33,8 +38,7 @@ describe('htm/babel', () => {
3338
test('basic nested transformation', () => {
3439
expect(
3540
transform('html`<a b=${2} ...${{ c: 3 }}>d: ${4}</a>`;', {
36-
babelrc: false,
37-
compact: true,
41+
...options,
3842
plugins: [
3943
[htmBabelPlugin, {
4044
useBuiltIns: true
@@ -43,24 +47,22 @@ describe('htm/babel', () => {
4347
}).code
4448
).toBe(`h("a",Object.assign({b:2},{c:3}),"d: ",4);`);
4549
});
46-
50+
4751
test('spread a single variable', () => {
4852
expect(
4953
transform('html`<a ...${foo}></a>`;', {
50-
babelrc: false,
51-
compact: true,
54+
...options,
5255
plugins: [
5356
htmBabelPlugin
5457
]
5558
}).code
5659
).toBe(`h("a",foo);`);
5760
});
58-
61+
5962
test('spread two variables', () => {
6063
expect(
6164
transform('html`<a ...${foo} ...${bar}></a>`;', {
62-
babelrc: false,
63-
compact: true,
65+
...options,
6466
plugins: [
6567
[htmBabelPlugin, {
6668
useBuiltIns: true
@@ -69,12 +71,11 @@ describe('htm/babel', () => {
6971
}).code
7072
).toBe(`h("a",Object.assign({},foo,bar));`);
7173
});
72-
74+
7375
test('property followed by a spread', () => {
7476
expect(
7577
transform('html`<a b="1" ...${foo}></a>`;', {
76-
babelrc: false,
77-
compact: true,
78+
...options,
7879
plugins: [
7980
[htmBabelPlugin, {
8081
useBuiltIns: true
@@ -83,12 +84,11 @@ describe('htm/babel', () => {
8384
}).code
8485
).toBe(`h("a",Object.assign({b:"1"},foo));`);
8586
});
86-
87+
8788
test('spread followed by a property', () => {
8889
expect(
8990
transform('html`<a ...${foo} b="1"></a>`;', {
90-
babelrc: false,
91-
compact: true,
91+
...options,
9292
plugins: [
9393
[htmBabelPlugin, {
9494
useBuiltIns: true
@@ -97,12 +97,11 @@ describe('htm/babel', () => {
9797
}).code
9898
).toBe(`h("a",Object.assign({},foo,{b:"1"}));`);
9999
});
100-
100+
101101
test('mix-and-match spreads', () => {
102102
expect(
103103
transform('html`<a b="1" ...${foo} c=${2} ...${{d:3}}></a>`;', {
104-
babelrc: false,
105-
compact: true,
104+
...options,
106105
plugins: [
107106
[htmBabelPlugin, {
108107
useBuiltIns: true
@@ -111,13 +110,12 @@ describe('htm/babel', () => {
111110
}).code
112111
).toBe(`h("a",Object.assign({b:"1"},foo,{c:2},{d:3}));`);
113112
});
114-
113+
115114
describe('{variableArity:false}', () => {
116115
test('should pass no children as an empty Array', () => {
117116
expect(
118117
transform('html`<div />`;', {
119-
babelrc: false,
120-
compact: true,
118+
...options,
121119
plugins: [
122120
[htmBabelPlugin, {
123121
variableArity: false
@@ -130,8 +128,7 @@ describe('htm/babel', () => {
130128
test('should pass children as an Array', () => {
131129
expect(
132130
transform('html`<div id=hello>hello</div>`;', {
133-
babelrc: false,
134-
compact: true,
131+
...options,
135132
plugins: [
136133
[htmBabelPlugin, {
137134
variableArity: false
@@ -146,8 +143,7 @@ describe('htm/babel', () => {
146143
test('should transform to inline vnodes', () => {
147144
expect(
148145
transform('var name="world",vnode=html`<div id=hello>hello, ${name}</div>`;', {
149-
babelrc: false,
150-
compact: true,
146+
...options,
151147
plugins: [
152148
[htmBabelPlugin, {
153149
pragma: false
@@ -162,8 +158,7 @@ describe('htm/babel', () => {
162158
test('should transform to monomorphic inline vnodes', () => {
163159
expect(
164160
transform('var name="world",vnode=html`<div id=hello>hello, ${name}</div>`;', {
165-
babelrc: false,
166-
compact: true,
161+
...options,
167162
plugins: [
168163
[htmBabelPlugin, {
169164
monomorphic: true
@@ -178,7 +173,7 @@ describe('htm/babel', () => {
178173
// Run all of the main tests against the Babel plugin:
179174
const mod = require('fs').readFileSync(require('path').resolve(__dirname, 'index.test.mjs'), 'utf8').replace(/\\0/g, '\0');
180175
const { code } = transform(mod.replace(/^\s*import\s*.+?\s*from\s+(['"]).*?\1[\s;]*$/im, 'const htm = function(){};'), {
181-
babelrc: false,
176+
...options,
182177
plugins: [htmBabelPlugin]
183178
});
184179
eval(code);

0 commit comments

Comments
 (0)