-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import path from 'node:path'; | ||
|
||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { findTemplate } from '../../src/api/init-scripts/find-template'; | ||
|
||
describe('findTemplate', () => { | ||
/** | ||
* Note: this test suite does not mock `require.resolve`. Instead, it uses | ||
* fixture dependencies defined in this module's package.json file to | ||
* actually resolve a local template. | ||
* | ||
* If you modify the fixtures, you may need to re-run `yarn install` in order | ||
* for the fixtures to be installed in your local `node_modules`. | ||
*/ | ||
describe('local modules', () => { | ||
it('should find an @electron-forge/template based on name', async () => { | ||
await expect(findTemplate('fixture')).resolves.toEqual({ name: 'electron-forge-template-fixture' }); | ||
}); | ||
it('should find an @electron-forge/template based on name', async () => { | ||
await expect(findTemplate('fixture-two')).resolves.toEqual({ name: 'electron-forge-template-fixture' }); | ||
}); | ||
it('should find an @electron-forge/template based on name', async () => { | ||
await expect(findTemplate('electron-forge-template-fixture-two')).resolves.toEqual({ name: 'electron-forge-template-fixture' }); | ||
}); | ||
}); | ||
|
||
/** | ||
* For global modules, we re-route the global NPM `node_modules` directory to | ||
* a folder in our fixture directory. Note that the folder _needs_ to be called | ||
* `node_modules` in order for the `require.resolve` custom path to work. | ||
*/ | ||
describe('global modules', () => { | ||
vi.mock(import('global-directory'), async (importOriginal) => { | ||
const mod = await importOriginal(); | ||
return { | ||
default: { | ||
...mod.default, | ||
npm: { | ||
...mod.default.npm, | ||
packages: path.resolve(__dirname, '..', 'fixture', 'global-stub', 'node_modules'), | ||
}, | ||
}, | ||
}; | ||
}); | ||
it('should find an @electron-forge/template based on name', async () => { | ||
await expect(findTemplate('global')).resolves.toEqual({ name: 'electron-forge-template-fixture-global' }); | ||
}); | ||
it('should find an electron-forge-template based on name', async () => { | ||
await expect(findTemplate('global-two')).resolves.toEqual({ name: 'electron-forge-template-fixture-global' }); | ||
}); | ||
}); | ||
|
||
it('should error if there are no valid templates', async () => { | ||
await expect(findTemplate('non-existent-template')).rejects.toThrowError('Failed to locate custom template: "non-existent-template".'); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
packages/api/core/spec/fixture/electron-forge-template-fixture/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = { name: 'electron-forge-template-fixture' }; |
5 changes: 5 additions & 0 deletions
5
packages/api/core/spec/fixture/electron-forge-template-fixture/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"main": "index.js", | ||
"type": "commonjs", | ||
"version": "13.3.7" | ||
} |
1 change: 1 addition & 0 deletions
1
...s/api/core/spec/fixture/global-stub/node_modules/@electron-forge/template-global/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...i/core/spec/fixture/global-stub/node_modules/@electron-forge/template-global/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...pi/core/spec/fixture/global-stub/node_modules/electron-forge-template-global-two/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...ore/spec/fixture/global-stub/node_modules/electron-forge-template-global-two/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters