Skip to content

Commit

Permalink
rollup tests finished
Browse files Browse the repository at this point in the history
  • Loading branch information
dconeybe committed Jan 18, 2024
1 parent 63693ce commit 1ae1d19
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 18 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/firestore/test/rollup/.mocharc.json
@@ -1,6 +1,6 @@
{
"extension": "ts",
"require": "ts-node/register",
"spec": "test.*ts",
"timeout": 10000
"spec": "test/**/*.test.ts",
"timeout": 60000
}
1 change: 1 addition & 0 deletions packages/firestore/test/rollup/bundle_id/package.json
Expand Up @@ -7,6 +7,7 @@
},
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@tsconfig/node16": "^16.1.1",
"rollup": "^4.9.5",
Expand Down
70 changes: 64 additions & 6 deletions packages/firestore/test/rollup/bundle_id/rollup.config.ts
@@ -1,22 +1,80 @@
import type { RollupOptions } from 'rollup';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

export default [
{
function browserCommonJsRollupOptions(): RollupOptions {
return {
input: 'index.cjs',
output: {
file: 'dist/index.browser.cjs',
format: 'cjs'
},
plugins: [commonjs(), nodeResolve({ browser: true })]
},
{
};
}

function browserESModuleRollupOptions(): RollupOptions {
return {
input: 'index.mjs',
output: {
file: 'dist/index.browser.mjs',
format: 'es'
},
plugins: [commonjs(), nodeResolve({ browser: true })]
}
] satisfies RollupOptions[];
};
}

function browserEsm5RollupOptions(): RollupOptions {
return {
input: 'index.mjs',
output: {
file: 'dist/index.browser.esm5.mjs',
format: 'es'
},
plugins: [
commonjs(),
nodeResolve({ browser: true, exportConditions: ['esm5'] })
]
};
}

function nodeCommonJsRollupOptions(): RollupOptions {
return {
input: 'index.cjs',
output: {
file: 'dist/index.node.cjs',
format: 'cjs'
},
plugins: [
json(),
commonjs(),
nodeResolve({ browser: false, exportConditions: ['node'] })
]
};
}

function nodeESModuleRollupOptions(): RollupOptions {
return {
input: 'index.mjs',
output: {
file: 'dist/index.node.mjs',
format: 'es'
},
plugins: [
json(),
commonjs(),
nodeResolve({ browser: false, exportConditions: ['node'] })
]
};
}

function* allRollupOptions(): Generator<RollupOptions> {
yield browserCommonJsRollupOptions();
yield browserESModuleRollupOptions();
yield browserEsm5RollupOptions();
yield nodeCommonJsRollupOptions();
yield nodeESModuleRollupOptions();
}

export default [...allRollupOptions()] satisfies RollupOptions[];
Expand Up @@ -2,39 +2,60 @@ import { expect } from 'chai';
import { execFileSync } from 'node:child_process';

Check failure on line 2 in packages/firestore/test/rollup/test/bundle_id.test.ts

View workflow job for this annotation

GitHub Actions / Lint

`node:child_process` import should occur before import of `chai`

// The path of the directory containing this file.
const bundleIdDir = `${__dirname}/bundle_id`;
const bundleIdDir = `${__dirname}/../bundle_id`;

describe('Rollup Tests', () => {
describe('bundle id in firestore bundles should match the expected', () => {
before(() => {
runNpmInstall(bundleIdDir);
runNpmRollup(bundleIdDir);
});

it('node.js commonjs scripts should use node.cjs bundle', () => {
it('node.js cjs scripts should use node cjs bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/index.cjs`,
expectedBundleId: 'fstrbid_node_cjs'
});
});

it('node.js esm scripts should use node.mjs bundle', () => {
it('node.js esm scripts should use node esm bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/index.mjs`,
expectedBundleId: 'fstrbid_node_esm'
});
});

it('browser esm scripts should use browser.mjs bundle', () => {
it('rollup browser cjs scripts should use browser cjs bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/dist/index.browser.cjs`,
expectedBundleId: 'fstrbid_browser_cjs'
});
});

it('rollup browser esm scripts should use browser esm bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/dist/index.browser.mjs`,
expectedBundleId: 'fstrbid_browser_esm'
});
});

it('browser commonjs scripts should use browser.cjs bundle', () => {
it('rollup browser esm5 scripts should use browser esm5 bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/dist/index.browser.cjs`,
expectedBundleId: 'fstrbid_browser_cjs'
jsScriptFile: `${bundleIdDir}/dist/index.browser.esm5.mjs`,
expectedBundleId: 'fstrbid_browser_esm5'
});
});

it('rollup node cjs scripts should use node cjs bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/dist/index.node.cjs`,
expectedBundleId: 'fstrbid_node_cjs'
});
});

it('rollup node esm scripts should use node esm bundle', () => {
verifyBundleId({
jsScriptFile: `${bundleIdDir}/dist/index.node.mjs`,
expectedBundleId: 'fstrbid_node_esm'
});
});
});
Expand Down

0 comments on commit 1ae1d19

Please sign in to comment.