Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(plugin-webpack): add tests for resolveForgeConfig #1447

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion packages/plugin/webpack/test/WebpackPlugin_spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { expect } from 'chai';
import { ForgeConfig } from '@electron-forge/shared-types';
import * as fs from 'fs-extra';
import * as path from 'path';
import { tmpdir } from 'os';

import { WebpackPluginConfig } from '../src/Config';
import WebpackPlugin from '../src/WebpackPlugin';

describe('WebpackPlugin', () => {
const baseConfig = {
const baseConfig: WebpackPluginConfig = {
mainConfig: {},
renderer: {
config: {},
Expand Down Expand Up @@ -58,4 +60,51 @@ describe('WebpackPlugin', () => {
await fs.remove(webpackTestDir);
});
});

describe('resolveForgeConfig', () => {
let plugin: WebpackPlugin;

before(() => {
plugin = new WebpackPlugin(baseConfig);
});

it('sets packagerConfig and packagerConfig.ignore if it does not exist', async () => {
const config = await plugin.resolveForgeConfig({} as ForgeConfig);
expect(config.packagerConfig).to.not.equal(undefined);
expect(config.packagerConfig.ignore).to.be.a('function');
});

describe('packagerConfig.ignore', () => {
it('does not overwrite an existing ignore value', async () => {
const config = await plugin.resolveForgeConfig({
packagerConfig: {
ignore: /test/,
},
} as ForgeConfig);

expect(config.packagerConfig.ignore).to.deep.equal(/test/);
});

it('ignores everything but files in .webpack', async () => {
const config = await plugin.resolveForgeConfig({} as ForgeConfig);
const ignore = config.packagerConfig.ignore as Function;

expect(ignore('')).to.equal(false);
expect(ignore('/abc')).to.equal(true);
expect(ignore('/.webpack')).to.equal(false);
expect(ignore('/.webpack/foo')).to.equal(false);
});

it('ignores files generated by jsonStats config', async () => {
const webpackConfig = { ...baseConfig, jsonStats: true };
webpackConfig.renderer.jsonStats = true;
plugin = new WebpackPlugin(webpackConfig);
const config = await plugin.resolveForgeConfig({} as ForgeConfig);
const ignore = config.packagerConfig.ignore as Function;

expect(ignore(path.join('foo', 'bar', '.webpack', 'main', 'stats.json'))).to.equal(true);
expect(ignore(path.join('foo', 'bar', '.webpack', 'renderer', 'stats.json'))).to.equal(true);
});
});
});
});