show an example that works without deasync (run with node --experimental-specifier-resolution=node .eslintrc.cjs)

This commit is contained in:
Joe Pea
2020-11-16 15:50:46 -08:00
parent 74ed14d8c4
commit 04432dd4d3
2 changed files with 12 additions and 11 deletions
+11 -10
View File
@@ -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 = {
},
],
};
}
+1 -1
View File
@@ -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');