Skip to content

Commit

Permalink
feat: remove preload.js from TypeScript templates (#2938)
Browse files Browse the repository at this point in the history
* fix: Remove preload.js files from TypeScript templates

* test: Add/update tests for ensuring js files are cleaned up from TypeScript templates

* chore: Apply prettier formatting and lints

* fix: add missing devDependencies to templates
  • Loading branch information
itsananderson committed Sep 28, 2022
1 parent cb1e560 commit 50484dc
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/template/typescript-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"fs-extra": "^10.0.0"
},
"devDependencies": {
"@electron-forge/test-utils": "6.0.0-beta.66"
"@electron-forge/test-utils": "6.0.0-beta.66",
"chai": "^4.3.3",
"fast-glob": "^3.2.7"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as testUtils from '@electron-forge/test-utils';
import fs from 'fs-extra';
import glob from 'fast-glob';
import path from 'path';
import template from '../src/TypeScriptWebpackTemplate';
import { expect } from 'chai';

describe('TypeScriptWebpackTemplate', () => {
let dir: string;
Expand Down Expand Up @@ -33,6 +35,11 @@ describe('TypeScriptWebpackTemplate', () => {
}
});

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', () => {
before(async () => {
await testUtils.ensureModulesInstalled(
Expand Down
3 changes: 2 additions & 1 deletion packages/template/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"devDependencies": {
"@electron-forge/test-utils": "6.0.0-beta.66",
"chai": "^4.3.3"
"chai": "^4.3.3",
"fast-glob": "^3.2.7"
}
}
2 changes: 2 additions & 0 deletions packages/template/typescript/src/TypeScriptTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class TypeScriptTemplate extends BaseTemplate {
await fs.remove(filePath('index.js'));
await this.copyTemplateFile(path.join(directory, 'src'), 'index.ts');

// Remove preload.js and replace with preload.ts
await fs.remove(filePath('preload.js'));
await this.copyTemplateFile(path.join(directory, 'src'), 'preload.ts');
});
}
Expand Down
10 changes: 5 additions & 5 deletions packages/template/typescript/test/TypeScriptTemplate_spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as testUtils from '@electron-forge/test-utils';
import { expect } from 'chai';
import fs from 'fs-extra';
import glob from 'fast-glob';
import path from 'path';
import template from '../src/TypeScriptTemplate';

Expand All @@ -16,18 +17,17 @@ describe('TypeScriptTemplate', () => {
});

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

it('should convert the main process file to typescript', async () => {
await testUtils.expectProjectPathNotExists(dir, path.join('src', 'index.js'), 'file');
await testUtils.expectProjectPathExists(dir, path.join('src', 'index.ts'), 'file');
expect((await fs.readFile(path.join(dir, 'src', 'index.ts'))).toString()).to.match(/import\b.*\bBrowserWindow\b/);
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', () => {
Expand Down

0 comments on commit 50484dc

Please sign in to comment.