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

feat: remove preload.js from TypeScript templates #2938

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
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