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

spec: add proper package test for webpack ts template #3040

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
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
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