From 04432dd4d3e079558aa1867b6ac9ef186082a834 Mon Sep 17 00:00:00 2001 From: Joe Pea Date: Mon, 16 Nov 2020 15:50:46 -0800 Subject: [PATCH] show an example that works without deasync (run with `node --experimental-specifier-resolution=node .eslintrc.cjs`) --- .eslintrc.cjs | 21 +++++++++++---------- jest.config.js | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index ee810017..22297d3a 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,23 +1,22 @@ -const deasync = require('deasync'); // powerful magic +main(); -const promiseSync = deasync((promise, cb) => { - console.log('wait for promise, before'); - promise +async function main() { + +const importSync = name => + // promiseSync( + import(name) .then(result => { console.log('promise resolved'); - cb(null, result); + return result; }) .catch(error => { console.log('promise error'); - cb(error); }); -}); - -const importSync = name => promiseSync(import(name)); +// ); // Look, no await needed here! console.log('import sync before'); -const jestConfig = importSync('./jest.config.js').default; +const jestConfig = (await importSync('./jest.config')).default; console.log('import sync after'); const testGlobals = {}; @@ -102,3 +101,5 @@ module.exports = { }, ], }; + +} diff --git a/jest.config.js b/jest.config.js index e66bfbd4..89f18fe7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ import path from 'path'; -import server from './test/config/server.js'; +import server from './test/config/server'; console.log('jest.config');