@mediatool/frontend-tools 1.2.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mtft.cjs CHANGED
@@ -3,20 +3,16 @@
3
3
 
4
4
  var commander = require('commander');
5
5
  var vite = require('vite');
6
- var promises = require('node:fs/promises');
7
- var node_path = require('node:path');
6
+ var promises = require('fs/promises');
7
+ var path = require('path');
8
8
  var ramda = require('ramda');
9
- var Mocha = require('mocha/lib/mocha.js');
10
- var runHelpers_js = require('mocha/lib/cli/run-helpers.js');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var Mocha__default = /*#__PURE__*/_interopDefaultLegacy(Mocha);
9
+ var module$1 = require('module');
10
+ var child_process = require('child_process');
15
11
 
16
12
  async function getModuleContext () {
17
13
  const location = process.cwd();
18
- const pkgLocation = node_path.resolve(location, './package.json');
19
- const entryLocation = node_path.resolve(location, './index.js');
14
+ const pkgLocation = path.resolve(location, './package.json');
15
+ const entryLocation = path.resolve(location, './index.js');
20
16
 
21
17
  try {
22
18
  await promises.stat(pkgLocation);
@@ -70,27 +66,41 @@ function build (type) {
70
66
  return fn()
71
67
  }
72
68
 
69
+ const require$1 = module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('mtft.cjs', document.baseURI).href)));
70
+ const mochaCliPath = require$1.resolve('mocha/lib/cli/cli.js');
71
+
73
72
  const extensions = '{js,jsx,ts,tsx}';
74
73
  const types = {
75
- all: `./{,!(node_modules)/**}/*-test.${extensions}`,
76
- unit: `./{,!(node_modules)/**}/test/unit/*-test.${extensions}`,
77
- it: `./{,!(node_modules)/**}/test/it/*-test.${extensions}`,
74
+ all: `./{,!(node_modules)/**}/**/*-test.${extensions}`,
75
+ unit: `./{,!(node_modules)/**}/test/unit/**/*-test.${extensions}`,
76
+ it: `./{,!(node_modules)/**}/test/it/**/*-test.${extensions}`,
78
77
  };
79
78
 
80
- async function test (typeOrSpec, options) {
81
- const { require = [] } = options;
79
+ async function test (typeOrSpec) {
82
80
  const spec = types[typeOrSpec] || typeOrSpec;
83
81
 
84
- const plugins = await runHelpers_js.handleRequires([
85
- '@mediatool/frontend-tools/lib/test/setup-mocha.cjs',
86
- ...require,
87
- ]);
88
- const opts = {
89
- spec: [ spec ],
90
- plugins,
91
- };
92
- const mocha = new Mocha__default["default"](opts);
93
- runHelpers_js.runMocha(mocha, opts);
82
+ const args = [
83
+ '--loader=tsx',
84
+ mochaCliPath,
85
+ spec,
86
+ '--require',
87
+ 'global-jsdom/register',
88
+ ];
89
+
90
+ const mochaProcess = child_process.spawn(process.execPath, args, { stdio: 'inherit' });
91
+
92
+ mochaProcess.on('exit', (code, signal) => {
93
+ process.on('exit', () => {
94
+ if (signal) {
95
+ process.kill(process.pid, signal);
96
+ } else {
97
+ process.exit(code);
98
+ }
99
+ });
100
+ });
101
+ process.on('SIGINT', () => {
102
+ mochaProcess.kill('SIGINT');
103
+ });
94
104
  }
95
105
 
96
106
  const program = new commander.Command();
@@ -1,5 +1,5 @@
1
- import { readFile, stat } from 'node:fs/promises'
2
- import { resolve } from 'node:path'
1
+ import { readFile, stat } from 'fs/promises'
2
+ import { resolve } from 'path'
3
3
  // eslint-disable-next-line import/no-extraneous-dependencies
4
4
  import { keys, uniq } from 'ramda'
5
5
 
package/lib/test/index.js CHANGED
@@ -1,25 +1,39 @@
1
- import Mocha from 'mocha/lib/mocha.js'
2
- import { handleRequires, runMocha } from 'mocha/lib/cli/run-helpers.js'
1
+ import { createRequire } from 'module'
2
+ import { spawn } from 'child_process'
3
+
4
+ const require = createRequire(import.meta.url)
5
+ const mochaCliPath = require.resolve('mocha/lib/cli/cli.js')
3
6
 
4
7
  const extensions = '{js,jsx,ts,tsx}'
5
8
  const types = {
6
- all: `./{,!(node_modules)/**}/*-test.${extensions}`,
7
- unit: `./{,!(node_modules)/**}/test/unit/*-test.${extensions}`,
8
- it: `./{,!(node_modules)/**}/test/it/*-test.${extensions}`,
9
+ all: `./{,!(node_modules)/**}/**/*-test.${extensions}`,
10
+ unit: `./{,!(node_modules)/**}/test/unit/**/*-test.${extensions}`,
11
+ it: `./{,!(node_modules)/**}/test/it/**/*-test.${extensions}`,
9
12
  }
10
13
 
11
- export default async function test (typeOrSpec, options) {
12
- const { require = [] } = options
14
+ export default async function test (typeOrSpec) {
13
15
  const spec = types[typeOrSpec] || typeOrSpec
14
16
 
15
- const plugins = await handleRequires([
16
- '@mediatool/frontend-tools/lib/test/setup-mocha.cjs',
17
- ...require,
18
- ])
19
- const opts = {
20
- spec: [ spec ],
21
- plugins,
22
- }
23
- const mocha = new Mocha(opts)
24
- runMocha(mocha, opts)
17
+ const args = [
18
+ '--loader=tsx',
19
+ mochaCliPath,
20
+ spec,
21
+ '--require',
22
+ 'global-jsdom/register',
23
+ ]
24
+
25
+ const mochaProcess = spawn(process.execPath, args, { stdio: 'inherit' })
26
+
27
+ mochaProcess.on('exit', (code, signal) => {
28
+ process.on('exit', () => {
29
+ if (signal) {
30
+ process.kill(process.pid, signal)
31
+ } else {
32
+ process.exit(code)
33
+ }
34
+ })
35
+ })
36
+ process.on('SIGINT', () => {
37
+ mochaProcess.kill('SIGINT')
38
+ })
25
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediatool/frontend-tools",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "Common configs and tooling for bundling, testing, linting frontend modules",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -20,11 +20,7 @@
20
20
  "mtft": "./dist/mtft.cjs"
21
21
  },
22
22
  "dependencies": {
23
- "@babel/core": "^7.20.2",
24
- "@babel/preset-env": "^7.20.2",
25
23
  "@babel/preset-react": "^7.18.6",
26
- "@babel/preset-typescript": "^7.18.6",
27
- "@babel/register": "^7.18.9",
28
24
  "@mediatool/eslint-config-mediatool": "^1.1.13",
29
25
  "@testing-library/react": "^13.4.0",
30
26
  "@testing-library/user-event": "^14.4.3",
@@ -36,6 +32,7 @@
36
32
  "global-jsdom": "^8.6.0",
37
33
  "jsdom": "^20.0.2",
38
34
  "mocha": "^10.1.0",
35
+ "tsx": "^3.12.7",
39
36
  "vite": "^3.2.4"
40
37
  },
41
38
  "peerDependencies": {
@@ -1,14 +0,0 @@
1
- /* eslint-env es6 */
2
- /* eslint-disable import/no-extraneous-dependencies */
3
- const babel = require('@babel/register').default
4
- const jsdom = require('global-jsdom')
5
-
6
- babel({
7
- presets: [
8
- '@babel/preset-env',
9
- '@babel/preset-react',
10
- '@babel/preset-typescript',
11
- ],
12
- extensions: [ '.ts', '.tsx', '.js', '.jsx' ],
13
- })
14
- jsdom()