Skip to content

Commit

Permalink
test: add test for creating esm/cjs configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
mato533 committed Dec 23, 2024
1 parent 8f43693 commit d58c451
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@wdio_electron-pkg-builder/test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('createRollupConfig', () => {
const compilerOptions = {
target: 'ESNext',
} as const;
const result = createRollupConfig(input, output, compilerOptions);
const result = createRollupConfig(input, output, compilerOptions, {});
expect(result.input).toStrictEqual(input);
expect(result.output).toStrictEqual(output);
});
Expand Down
31 changes: 29 additions & 2 deletions packages/@wdio_electron-pkg-builder/test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { dirname } from 'node:path';

import { createRollupConfig } from '../src/index';
import { createCjsRollupOptions, createEsmRollupOptions, createRollupConfig } from '../src/index';
import { getFixturePackagePath } from './utils';
import { rollup } from 'rollup';

describe('getBuildConfigs', () => {
describe('createRollupConfig', () => {
it('should return 2 configuration objects', () => {
const fixture = getFixturePackagePath('esm', 'build-success-esm');
const cwd = dirname(fixture);
const result = createRollupConfig({ rootDir: cwd });

expect(result.length).toBe(2);
// @ts-ignore
expect(result[0].output!.format).toBe('esm');
// @ts-ignore
expect(result[1].output!.format).toBe('cjs');
});

it('should fail to load package.json that is not existed', () => {
Expand All @@ -31,3 +36,25 @@ describe('getBuildConfigs', () => {
await expect(() => bundle.generate({})).rejects.toThrowError();
});
});

describe('createEsmOutputConfig', () => {
it('should return configuration for ESM', () => {
const fixture = getFixturePackagePath('esm', 'build-success-esm');
const cwd = dirname(fixture);
const result = createEsmRollupOptions({ rootDir: cwd });

// @ts-ignore
expect(result.output!.format).toBe('esm');
});
});

describe('createCjsOutputConfig', () => {
it('should return configuration for ESM', () => {
const fixture = getFixturePackagePath('esm', 'build-success-esm');
const cwd = dirname(fixture);
const result = createCjsRollupOptions({ rootDir: cwd });

// @ts-ignore
expect(result.output!.format).toBe('cjs');
});
});

0 comments on commit d58c451

Please sign in to comment.