Skip to content

Commit d5199c3

Browse files
Update test setup (#188)
* Add .test suffix to test files * Move dedent helper to test-utils * Move global test setup code to setup.js
1 parent 2a6f332 commit d5199c3

File tree

9 files changed

+25
-34
lines changed

9 files changed

+25
-34
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"transpile:jsx": "microbundle src/jsx.js -o dist/jsx.js --target web --external none && microbundle dist/jsx.js -o dist/jsx.js -f cjs",
3030
"copy-typescript-definition": "copyfiles -f src/*.d.ts dist",
3131
"test": "eslint src test && tsc && npm run test:mocha",
32-
"test:mocha": "mocha -r @babel/register test/**/*.js",
32+
"test:mocha": "mocha -r @babel/register -r test/setup.js test/**/*.test.js",
3333
"format": "prettier src/**/*.{d.ts,js} test/**/*.js --write",
3434
"prepublishOnly": "npm run build",
3535
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"

test/context.js renamed to test/context.test.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import render from '../src/jsx';
22
import { h, createContext, Component } from 'preact';
3-
import chai, { expect } from 'chai';
4-
import sinonChai from 'sinon-chai';
5-
chai.use(sinonChai);
6-
7-
// tag to remove leading whitespace from tagged template literal
8-
function dedent([str]) {
9-
return str
10-
.split('\n' + str.match(/^\n*(\s+)/)[1])
11-
.join('\n')
12-
.replace(/(^\n+|\n+\s*$)/g, '');
13-
}
3+
import { expect } from 'chai';
4+
import { dedent } from './utils';
145

156
describe('context', () => {
167
let renderJsx = (jsx, opts) => render(jsx, null, opts).replace(/ {2}/g, '\t');
File renamed without changes.

test/jsx.js renamed to test/jsx.test.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
import render from '../src/jsx';
22
import { h } from 'preact';
3-
import chai, { expect } from 'chai';
4-
import sinonChai from 'sinon-chai';
5-
chai.use(sinonChai);
6-
7-
// tag to remove leading whitespace from tagged template literal
8-
// eslint-disable-next-line jest/no-export
9-
export function dedent([str]) {
10-
return str
11-
.split('\n' + str.match(/^\n*(\s+)/)[1])
12-
.join('\n')
13-
.replace(/(^\n+|\n+\s*$)/g, '');
14-
}
3+
import { expect } from 'chai';
4+
import { dedent } from './utils';
155

166
describe('jsx', () => {
177
let renderJsx = (jsx, opts) => render(jsx, null, opts).replace(/ {2}/g, '\t');

test/pretty.js renamed to test/pretty.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { render as basicRender } from '../src';
22
import { render } from '../src/jsx';
33
import { h, Fragment } from 'preact';
4-
import chai, { expect } from 'chai';
5-
import sinonChai from 'sinon-chai';
6-
import { dedent } from './jsx';
7-
chai.use(sinonChai);
4+
import { expect } from 'chai';
5+
import { dedent } from './utils';
86

97
describe('pretty', () => {
108
let prettyRender = (jsx) => render(jsx, {}, { pretty: true });

test/render.js renamed to test/render.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { render, shallowRender } from '../src';
22
import { h, Component, createContext, Fragment, options } from 'preact';
33
import { useState, useContext, useEffect, useLayoutEffect } from 'preact/hooks';
4-
import chai, { expect } from 'chai';
4+
import { expect } from 'chai';
55
import { spy, stub, match } from 'sinon';
6-
import sinonChai from 'sinon-chai';
7-
chai.use(sinonChai);
86

97
describe('render', () => {
108
describe('Basic JSX', () => {

test/setup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import chai from 'chai';
2+
import sinonChai from 'sinon-chai';
3+
4+
chai.use(sinonChai);

test/shallowRender.js renamed to test/shallowRender.test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { shallowRender } from '../src';
22
import { h, Fragment } from 'preact';
3-
import chai, { expect } from 'chai';
3+
import { expect } from 'chai';
44
import { spy } from 'sinon';
5-
import sinonChai from 'sinon-chai';
6-
chai.use(sinonChai);
75

86
describe('shallowRender()', () => {
97
it('should not render nested components', () => {

test/utils.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* tag to remove leading whitespace from tagged template
3+
* literal.
4+
* @param {TemplateStringsArray}
5+
* @returns {string}
6+
*/
7+
export function dedent([str]) {
8+
return str
9+
.split('\n' + str.match(/^\n*(\s+)/)[1])
10+
.join('\n')
11+
.replace(/(^\n+|\n+\s*$)/g, '');
12+
}

0 commit comments

Comments
 (0)