Skip to content

Commit

Permalink
spec: add proper package test for webpack ts template (#3040)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarshallOfSound committed Nov 1, 2022
1 parent a89ed7d commit 6e9cca3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/template/webpack-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@electron-forge/core-utils": "^6.0.0-beta.73",
"@electron-forge/maker-deb": "6.0.0-beta.73",
"@electron-forge/maker-rpm": "6.0.0-beta.73",
"@electron-forge/maker-squirrel": "6.0.0-beta.73",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path';

import { yarnOrNpmSpawn } from '@electron-forge/core-utils';
import * as testUtils from '@electron-forge/test-utils';
import { expect } from 'chai';
import glob from 'fast-glob';
import fs from 'fs-extra';

import { api } from '../../../api/core';
import template from '../src/WebpackTypeScriptTemplate';

describe('WebpackTypeScriptTemplate', () => {
let dir: string;
Expand Down Expand Up @@ -49,19 +49,42 @@ describe('WebpackTypeScriptTemplate', () => {
});

describe('lint', () => {
it('should initially pass the linting process', async () => {
delete process.env.TS_NODE_PROJECT;
await testUtils.expectLintToPass(dir);
});
});

describe('package', () => {
let cwd: string;

before(async () => {
delete process.env.TS_NODE_PROJECT;
await testUtils.ensureModulesInstalled(
dir,
['electron', 'electron-squirrel-startup'],
template.devDependencies
.filter((moduleName) => moduleName.includes('eslint') || moduleName.includes('typescript'))
.concat(['@electron-forge/plugin-webpack'])
);
// Webpack resolves plugins via cwd
cwd = process.cwd();
process.chdir(dir);
// We need the version of webpack to match exactly during development due to a quirk in
// typescript type-resolution. In prod no one has to worry about things like this
const pj = await fs.readJson(path.resolve(dir, 'package.json'));
pj.resolutions = {
// eslint-disable-next-line @typescript-eslint/no-var-requires
webpack: `${require('../../../plugin/webpack/node_modules/webpack/package.json').version}`,
};
await fs.writeJson(path.resolve(dir, 'package.json'), pj);
await yarnOrNpmSpawn(['install'], {
cwd: dir,
});
});

it('should initially pass the linting process', async () => {
await testUtils.expectLintToPass(dir);
after(() => {
process.chdir(cwd);
});

it('should pass', async () => {
await api.package({
dir,
interactive: false,
});
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async function runNPM(dir: string, ...args: string[]) {
await spawn('npm', args, { cwd: dir });
}

async function runNPMInstall(dir: string, ...args: string[]) {
export async function runNPMInstall(dir: string, ...args: string[]) {
await runNPM(dir, 'install', ...args);
}

Expand Down

0 comments on commit 6e9cca3

Please sign in to comment.