Skip to content

Commit 44f8a8d

Browse files
committed
WIP (this commit will be re-written): update use native Node ESM for server code, update config files to specifically use .cjs (those tools don't support Node ESM files yet), use a single eslintrc file, all test code uses ESM import/export syntax instead of require (WIP)
1 parent c354bce commit 44f8a8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+919
-480
lines changed

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
const deasync = require('deasync'); // powerful magic
2+
3+
const promiseSync = deasync((promise, cb) => {
4+
promise.then((result) => cb(null, result)).catch((error) => cb(error));
5+
});
6+
7+
const importSync = (name) => promiseSync(import(name));
8+
9+
// Look, no await needed here!
10+
const jestConfig = importSync('./jest.config').default;
11+
12+
const testGlobals = {};
13+
14+
for (const key of Object.keys(jestConfig.globals)) {
15+
testGlobals[key] = 'readonly';
16+
}
17+
118
module.exports = {
219
root: true,
320
parser: 'babel-eslint',
@@ -39,6 +56,7 @@ module.exports = {
3956
'no-var': ['error'],
4057
'no-void': ['error'],
4158
'no-with': ['error'],
59+
'no-prototype-builtins': 'off',
4260
radix: ['error'],
4361
'spaced-comment': ['error', 'always'],
4462
strict: ['error', 'global'],
@@ -60,4 +78,16 @@ module.exports = {
6078
$docsify: 'writable',
6179
dom: 'writable',
6280
},
81+
82+
overrides: [
83+
{
84+
files: ['test/**/*.js', '**/*.test.js'],
85+
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
86+
globals: testGlobals,
87+
},
88+
{
89+
files: ['test/e2e/**/*.test.js'],
90+
extends: ['plugin:jest-playwright/recommended'],
91+
},
92+
],
6393
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
module.exports = {
22
singleQuote: true,
33
trailingComma: 'es5',
4+
useTabs: false,
5+
tabWidth: 2,
46
};

babel.config.cjs

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+
};

babel.config.js

Lines changed: 0 additions & 12 deletions
This file was deleted.

jest.config.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
const path = require('path');
2-
const { globals: serverGlobals } = require('./test/config/server.js');
1+
import path from 'path';
2+
import server from './test/config/server';
3+
4+
const { globals: serverGlobals } = server;
5+
const dirname = path.dirname(import.meta.url.replace('file://', ''));
36

47
const sharedConfig = {
58
errorOnDeprecated: true,
69
globals: {
710
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST
8-
DOCS_PATH: path.resolve(__dirname, 'docs'),
9-
LIB_PATH: path.resolve(__dirname, 'lib'),
10-
SRC_PATH: path.resolve(__dirname, 'src'),
11+
DOCS_PATH: path.resolve(dirname, 'docs'),
12+
LIB_PATH: path.resolve(dirname, 'lib'),
13+
SRC_PATH: path.resolve(dirname, 'src'),
1114
},
12-
globalSetup: './test/config/jest.setup.js',
13-
globalTeardown: './test/config/jest.teardown.js',
15+
globalSetup: './test/config/jest.setup.cjs',
16+
globalTeardown: './test/config/jest.teardown.cjs',
1417
resetModules: true,
1518
restoreMocks: true,
1619
};
1720

18-
module.exports = {
19-
// Adding globals to config root for easier importing into .eslint.js, but
21+
// Jest configuration: https://jestjs.io/docs/en/configuration
22+
23+
export default {
24+
// Disable transforms, we'll write plain JS. This is also needed for native
25+
// ESM (see https://jestjs.io/docs/en/ecmascript-modules).
26+
transform: {},
27+
28+
// Adding globals to config root for easier importing into .eslint.cjs, but
2029
// as of Jest 26.4.2 these globals need to be added to each project config
2130
// as well.
2231
globals: sharedConfig.globals,

0 commit comments

Comments
 (0)