From 6e9cca35796676753a824a39933ef1bcc0450ce6 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 31 Oct 2022 18:02:20 -0700 Subject: [PATCH] spec: add proper package test for webpack ts template (#3040) --- .../template/webpack-typescript/package.json | 1 + .../test/WebpackTypeScript_spec_slow.ts | 43 ++++++++++++++----- packages/utils/test-utils/src/index.ts | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/packages/template/webpack-typescript/package.json b/packages/template/webpack-typescript/package.json index 07182be9c6..df5a2f3da4 100644 --- a/packages/template/webpack-typescript/package.json +++ b/packages/template/webpack-typescript/package.json @@ -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", diff --git a/packages/template/webpack-typescript/test/WebpackTypeScript_spec_slow.ts b/packages/template/webpack-typescript/test/WebpackTypeScript_spec_slow.ts index 8bf643a49c..61066c9647 100644 --- a/packages/template/webpack-typescript/test/WebpackTypeScript_spec_slow.ts +++ b/packages/template/webpack-typescript/test/WebpackTypeScript_spec_slow.ts @@ -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; @@ -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, + }); }); }); diff --git a/packages/utils/test-utils/src/index.ts b/packages/utils/test-utils/src/index.ts index 7c722e12bb..df03c252d4 100644 --- a/packages/utils/test-utils/src/index.ts +++ b/packages/utils/test-utils/src/index.ts @@ -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); }