Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
presets: [
[
'@babel/preset-env', {
corejs: { version: 3, proposals: true },
useBuiltIns: 'usage'
}
],
'@babel/preset-react'
],
only: [
'test/**/*',
'src/**/*'
]
};
11 changes: 11 additions & 0 deletions mocha.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"require": [
"test/helper.js",
"@babel/register"
],
"extension": [ "js", "jsx", "ts", "tsx" ],
"checkLeaks": true,
"recursive": true,
"colors": true,
"R": "spec"
}
23 changes: 20 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
{
"dependencies": {
"ts-node": "latest",
"typescript": "latest"
"name": "node-16-hangs",
"license": "MIT",
"scripts": {
"test": "env NODE_ENV=test mocha --config mocha.json 'test/**/*.js?(x)'"
},
"devDependencies": {
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@babel/preset-react": "^7.14.5",
"@babel/register": "^7.15.3",
"@testing-library/react": "^12.1.0",
"chai": "^4.3.4",
"core-js": "^3.17.3",
"jsdom": "^17.0.0",
"mocha": "^9.1.1",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"engines": {
"node": ">=14"
}
}
5 changes: 1 addition & 4 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
n lts

# Install package.json dependencies
yarn

# Run ts-node
yarn ts-node ./example.ts
yarn test

echo "Process exited with code: $?"
echo
Expand Down
11 changes: 11 additions & 0 deletions src/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

// ---------------------------------------------------------------------

const TestComponent = ({ message }) => {
return (
<div>{message}</div>
);
};

export default TestComponent;
12 changes: 12 additions & 0 deletions test/component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { render, screen } from '@testing-library/react';
import Component from '../src/component';
import { expect } from 'chai';
import React from 'react';

// ---------------------------------------------------------------------

it('the test', () => {
render(<Component message="foo" />);

expect(screen.queryByText('foo')).to.not.eq(null)
});
11 changes: 11 additions & 0 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://enzymejs.github.io/enzyme/docs/guides/jsdom.html

const { JSDOM } = require('jsdom');

const jsdom = new JSDOM('<!doctype html><html><body></body></html>', {
url: 'http://localhost/'
});

global.navigator = { userAgent: 'node.js' };
global.document = jsdom.window.document;
global.window = jsdom.window;
28 changes: 28 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"include": [ "src", "types" ],
"compilerOptions": {
"module": "esnext",
"lib": [ "dom", "esnext" ],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true
},
"ts-node": {
"compilerOptions": {
"module": "commonjs"
},
"transpileOnly": true
}
}
Loading