Skip to content

Commit

Permalink
WIP (this commit will be re-written): update use native Node ESM for …
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
trusktr committed Nov 7, 2020
1 parent c354bce commit 44f8a8d
Show file tree
Hide file tree
Showing 75 changed files with 919 additions and 480 deletions.
30 changes: 30 additions & 0 deletions .eslintrc.js → .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
const deasync = require('deasync'); // powerful magic

const promiseSync = deasync((promise, cb) => {
promise.then((result) => cb(null, result)).catch((error) => cb(error));
});

const importSync = (name) => promiseSync(import(name));

// Look, no await needed here!
const jestConfig = importSync('./jest.config').default;

const testGlobals = {};

for (const key of Object.keys(jestConfig.globals)) {
testGlobals[key] = 'readonly';
}

module.exports = {
root: true,
parser: 'babel-eslint',
Expand Down Expand Up @@ -39,6 +56,7 @@ module.exports = {
'no-var': ['error'],
'no-void': ['error'],
'no-with': ['error'],
'no-prototype-builtins': 'off',
radix: ['error'],
'spaced-comment': ['error', 'always'],
strict: ['error', 'global'],
Expand All @@ -60,4 +78,16 @@ module.exports = {
$docsify: 'writable',
dom: 'writable',
},

overrides: [
{
files: ['test/**/*.js', '**/*.test.js'],
extends: ['plugin:jest/recommended', 'plugin:jest/style'],
globals: testGlobals,
},
{
files: ['test/e2e/**/*.test.js'],
extends: ['plugin:jest-playwright/recommended'],
},
],
};
2 changes: 2 additions & 0 deletions .prettierrc.js → .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
singleQuote: true,
trailingComma: 'es5',
useTabs: false,
tabWidth: 2,
};
12 changes: 12 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
// presets: [
// [
// '@babel/preset-env',
// {
// targets: {
// node: 'current',
// },
// },
// ],
// ],
};
12 changes: 0 additions & 12 deletions babel.config.js

This file was deleted.

27 changes: 18 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
const path = require('path');
const { globals: serverGlobals } = require('./test/config/server.js');
import path from 'path';
import server from './test/config/server';

const { globals: serverGlobals } = server;
const dirname = path.dirname(import.meta.url.replace('file://', ''));

const sharedConfig = {
errorOnDeprecated: true,
globals: {
...serverGlobals, // BLANK_URL, DOCS_URL, LIB_URL, NODE_MODULES_URL, TEST_HOST
DOCS_PATH: path.resolve(__dirname, 'docs'),
LIB_PATH: path.resolve(__dirname, 'lib'),
SRC_PATH: path.resolve(__dirname, 'src'),
DOCS_PATH: path.resolve(dirname, 'docs'),
LIB_PATH: path.resolve(dirname, 'lib'),
SRC_PATH: path.resolve(dirname, 'src'),
},
globalSetup: './test/config/jest.setup.js',
globalTeardown: './test/config/jest.teardown.js',
globalSetup: './test/config/jest.setup.cjs',
globalTeardown: './test/config/jest.teardown.cjs',
resetModules: true,
restoreMocks: true,
};

module.exports = {
// Adding globals to config root for easier importing into .eslint.js, but
// Jest configuration: https://jestjs.io/docs/en/configuration

export default {
// Disable transforms, we'll write plain JS. This is also needed for native
// ESM (see https://jestjs.io/docs/en/ecmascript-modules).
transform: {},

// Adding globals to config root for easier importing into .eslint.cjs, but
// as of Jest 26.4.2 these globals need to be added to each project config
// as well.
globals: sharedConfig.globals,
Expand Down
Loading

0 comments on commit 44f8a8d

Please sign in to comment.