Skip to content

Commit

Permalink
fix: use default and named exports exclusively (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Dec 8, 2023
1 parent 20e7682 commit e0b8489
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 73 deletions.
2 changes: 1 addition & 1 deletion e2e/testEnvironment.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const TestEnvironment = require('jest-environment-emit/node').default;
const TestEnvironment = require('jest-environment-emit/node');

class E2ETestEnvironment extends TestEnvironment {
constructor(config, context) {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/index');
module.exports = require('./dist/index').default;
3 changes: 1 addition & 2 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import index from './dist/index.js';

const { WithEmitter } = index;
const { default: WithEmitter } = index;

export { WithEmitter };
export default WithEmitter;
3 changes: 1 addition & 2 deletions jsdom.js
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/* Jest 27 fallback */
module.exports = require('./dist/jsdom');
module.exports = require('./dist/jsdom').default;
3 changes: 1 addition & 2 deletions jsdom.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import jsdom from './dist/jsdom.js';

const { TestEnvironment } = jsdom;
const { default: TestEnvironment } = jsdom;

export { TestEnvironment };
export default TestEnvironment;

2 changes: 1 addition & 1 deletion node.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./dist/node');
module.exports = require('./dist/node').default;
3 changes: 1 addition & 2 deletions node.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import node from './dist/node.js';

const { TestEnvironment } = node;
const { default: TestEnvironment } = node;

export { TestEnvironment };
export default TestEnvironment;
3 changes: 0 additions & 3 deletions package-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
},
"dependencies": {
"jest-environment-emit": "file:../jest-environment-emit-1.0.0.tgz"
},
"devDependencies": {
"typescript": "^5.3.3"
}
}
15 changes: 6 additions & 9 deletions package-e2e/test.cjs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
const assert = require('assert');

const index = require('jest-environment-emit');
assert(typeof index.default === 'function', 'jest-environment-emit should have a function as its default export');
assert.strictEqual(index.default, index.WithEmitter, 'jest-environment-emit should have a named alternative to its default export');
const WithEmitter = require('jest-environment-emit');
assert(typeof WithEmitter === 'function', 'jest-environment-emit should have a function as its default export');

const jsdom = require('jest-environment-emit/jsdom');
assert(typeof jsdom.default === 'function', 'jest-environment-emit/jsdom should have a function as its default export');
assert.strictEqual(jsdom.default, jsdom.TestEnvironment, 'jest-environment-emit/jsdom should have a named export `TestEnvironment`');
const JestEnvironmentEmitJsDOM = require('jest-environment-emit/jsdom');
assert(typeof JestEnvironmentEmitJsDOM === 'function', 'jest-environment-emit/jsdom should have a function as its default export');

const node = require('jest-environment-emit/node');
assert(typeof node.default === 'function', 'jest-environment-emit/node should have a function as its default export');
assert.strictEqual(node.default, node.TestEnvironment, 'jest-environment-emit/node should have a named export `TestEnvironment`');
const JestEnvironmentEmitNode = require('jest-environment-emit/node');
assert(typeof JestEnvironmentEmitNode === 'function', 'jest-environment-emit/node should have a function as its default export');

const debug = require('jest-environment-emit/debug');
assert(typeof debug.aggregateLogs === 'function', 'jest-environment-emit/debug should have a named export `aggregateLogs`');
16 changes: 0 additions & 16 deletions package-e2e/test.js

This file was deleted.

25 changes: 9 additions & 16 deletions package-e2e/test.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import assert from 'assert';

const index = await import('jest-environment-emit');
assert(typeof index.default === 'function', 'jest-environment-emit should have a function as its default export');
assert.strictEqual(index.default, index.WithEmitter, 'jest-environment-emit should have a named alternative to its default export');

const jsdom = await import('jest-environment-emit/jsdom');
assert(typeof jsdom.default === 'function', 'jest-environment-emit/jsdom should have a function as its default export');
assert.strictEqual(jsdom.default, jsdom.TestEnvironment, 'jest-environment-emit/jsdom should have a named export `TestEnvironment`');

const node = await import('jest-environment-emit/node');
assert(typeof node.default === 'function', 'jest-environment-emit/node should have a function as its default export');
assert.strictEqual(node.default, node.TestEnvironment, 'jest-environment-emit/node should have a named export `TestEnvironment`');

const debug = await import('jest-environment-emit/debug');
assert(typeof debug.aggregateLogs === 'function', 'jest-environment-emit/debug should have a named export `aggregateLogs`');

import WithEmitter from 'jest-environment-emit';
import JestEnvironmentEmitJsDOM from 'jest-environment-emit/jsdom';
import JestEnvironmentEmitNode from 'jest-environment-emit/node';
import { aggregateLogs } from 'jest-environment-emit/debug';

assert(typeof WithEmitter === 'function', 'jest-environment-emit should have a function as its default export');
assert(typeof JestEnvironmentEmitJsDOM === 'function', 'jest-environment-emit/jsdom should have a function as its default export');
assert(typeof JestEnvironmentEmitNode === 'function', 'jest-environment-emit/node should have a function as its default export');
assert(typeof aggregateLogs === 'function', 'jest-environment-emit/debug should have a named export `aggregateLogs`');
17 changes: 11 additions & 6 deletions package-e2e/test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import WithEmitter, { WithEmitter as WithEmitterNamed } from 'jest-environment-emit';
import JsdomTestEnvironment, { TestEnvironment as JsdomTestEnvironmentNamed } from 'jest-environment-emit/jsdom';
import NodeTestEnvironment, { TestEnvironment as NodeTestEnvironmentNamed } from 'jest-environment-emit/node';
import WithEmitter from 'jest-environment-emit';
import type { EnvironmentListenerFn } from 'jest-environment-emit';
import JsdomTestEnvironment from 'jest-environment-emit/jsdom';
import NodeTestEnvironment from 'jest-environment-emit/node';
import { aggregateLogs } from 'jest-environment-emit/debug';

function assertType<T>(_actual: T): void {
// no-op
}

assertType<Function>(WithEmitter);
assertType<Function>(WithEmitterNamed);
assertType<Function>(JsdomTestEnvironment);
assertType<Function>(JsdomTestEnvironmentNamed);
assertType<Function>(NodeTestEnvironment);
assertType<Function>(NodeTestEnvironmentNamed);
assertType<Function>(aggregateLogs);

assertType<EnvironmentListenerFn>((context, options) => {
context.env.global.__INJECT__ = options;
context.testEvents.on('test_start', ({ event, state }) => {
console.log(event.test.fn.toString(), state.rootDescribeBlock.name, options);
});
});
7 changes: 1 addition & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export * from './types';
* });
*/

export function WithEmitter<E extends JestEnvironment>(
export default function WithEmitter<E extends JestEnvironment>(
JestEnvironmentClass: new (...args: any[]) => E,
callback?: EnvironmentListenerFn<E>,
MixinName = 'WithEmitter',
Expand Down Expand Up @@ -125,8 +125,3 @@ export type WithEmitterClass<E extends JestEnvironment> = (new (
) => WithTestEvents<E>) & {
derive(callback: EnvironmentListener<E>, ClassName?: string): WithEmitterClass<E>;
};

/**
* @inheritDoc
*/
export default WithEmitter;
5 changes: 2 additions & 3 deletions src/jsdom.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import JestEnvironmentJsdom from 'jest-environment-jsdom';
import { WithEmitter } from './index';
import WithEmitter from './index';

export const TestEnvironment = WithEmitter(JestEnvironmentJsdom);
export default TestEnvironment;
export default WithEmitter(JestEnvironmentJsdom);
5 changes: 2 additions & 3 deletions src/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import JestEnvironmentNode from 'jest-environment-node';
import { WithEmitter } from './index';
import WithEmitter from './index';

export const TestEnvironment = WithEmitter(JestEnvironmentNode);
export default TestEnvironment;
export default WithEmitter(JestEnvironmentNode);

0 comments on commit e0b8489

Please sign in to comment.