Skip to content

Commit

Permalink
faet: add test for vite-typescript template
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Mar 4, 2023
1 parent dc73cde commit 73853b4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/template/vite-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
},
"devDependencies": {
"@electron-forge/core-utils": "6.0.5",
"@electron-forge/maker-deb": "6.0.5",
"@electron-forge/maker-rpm": "6.0.5",
"@electron-forge/maker-squirrel": "6.0.5",
"@electron-forge/maker-zip": "6.0.5",
"@electron-forge/test-utils": "6.0.5",
"electron-forge-plugin-vite": "latest",
"chai": "^4.3.3",
"fast-glob": "^3.2.7"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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';

describe('ViteTypeScriptTemplate', () => {
let dir: string;

before(async () => {
dir = await testUtils.ensureTestDirIsNonexistent();
});

it('should succeed in initializing the typescript template', async () => {
await api.init({
dir,
template: path.resolve(__dirname, '..', 'src', 'ViteTypeScriptTemplate'),
interactive: false,
});
});

context('template files are copied to project', () => {
const expectedFiles = [
'tsconfig.json',
'.eslintrc.json',
'forge.config.ts',
'vite.main.config.ts',
'vite.renderer.config.ts',
'vite.preload.config.ts',
path.join('src', 'main.ts'),
path.join('src', 'renderer.ts'),
path.join('src', 'preload.ts'),
];
for (const filename of expectedFiles) {
it(`${filename} should exist`, async () => {
await testUtils.expectProjectPathExists(dir, filename, 'file');
});
}
});

it('should ensure js source files from base template are removed', async () => {
const jsFiles = await glob(path.join(dir, 'src', '**', '*.js'));
expect(jsFiles.length).to.equal(0, `The following unexpected js files were found in the src/ folder: ${JSON.stringify(jsFiles)}`);
});

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;
// Vite resolves plugins via cwd
cwd = process.cwd();
process.chdir(dir);
// We need the version of vite 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
vite: `${require('../../../../node_modules/vite/package.json').version}`,
};
await fs.writeJson(path.resolve(dir, 'package.json'), pj);
await yarnOrNpmSpawn(['install'], {
cwd: dir,
});
});

after(() => {
process.chdir(cwd);
});

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

after(async () => {
await fs.remove(dir);
});
});
2 changes: 1 addition & 1 deletion packages/template/vite-typescript/tmpl/forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MakerSquirrel } from '@electron-forge/maker-squirrel';
import { MakerZIP } from '@electron-forge/maker-zip';
import { MakerDeb } from '@electron-forge/maker-deb';
import { MakerRpm } from '@electron-forge/maker-rpm';
import { VitePlugin } from '@electron-forge/plugin-vite';
import { VitePlugin } from 'electron-forge-plugin-vite';

const config: ForgeConfig = {
packagerConfig: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/template/vite-typescript/tmpl/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"@electron-forge/plugin-vite": "ELECTRON_FORGE/VERSION",
"electron-forge-plugin-vite": "latest",
"ts-node": "^10.0.0",
"typescript": "~4.5.4"
}
Expand Down

0 comments on commit 73853b4

Please sign in to comment.