-
Notifications
You must be signed in to change notification settings - Fork 14
chore: mock import module in favour of bundle require #1234
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
Open
BioPhoton
wants to merge
9
commits into
main
Choose a base branch
from
chore/mock-import-module
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−199
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7f473ec
fix: avoid bundle require mocking in tests
BioPhoton 1b205be
fix: avoid depending on central mock files
BioPhoton 18a6c40
fix: delete centralised mock files
BioPhoton 27f92ed
refactor: resolve lint issues
BioPhoton b06c96b
refactor: add defaults for backwards compat
BioPhoton 30802a5
Update packages/plugin-lighthouse/src/lib/runner/utils.unit.test.ts
BioPhoton e8c4526
refactor: wip
BioPhoton e2685b3
refactor: wip
BioPhoton 48e900f
refactor: remove redundant tests
BioPhoton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
packages/cli/mocks/configs/code-pushup.needs-tsconfig.config.ts
This file contains hidden or 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,12 @@ | ||
| // the point is to test runtime import which requires tsconfig for path aliases | ||
|
|
||
| /* eslint-disable import/no-unresolved */ | ||
| // @ts-expect-error - test tsconfig paths missing in config | ||
| import customPlugin from '@example/custom-plugin'; | ||
|
|
||
| /* eslint-enable import/no-unresolved */ | ||
| const config = { | ||
| plugins: [customPlugin], | ||
| }; | ||
|
|
||
| export default config; |
File renamed without changes.
This file contains hidden or 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,11 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "allowImportingTsExtensions": true, | ||
| "moduleResolution": "node", | ||
| "paths": { | ||
| "@example/custom-plugin": ["./custom-plugin.ts"] | ||
| } | ||
| }, | ||
| "include": ["*.ts"] | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,12 +8,8 @@ const configDirPath = path.join( | |
| '..', | ||
| '..', | ||
| '..', | ||
| '..', | ||
| 'testing', | ||
| 'test-fixtures', | ||
| 'src', | ||
| 'lib', | ||
| 'fixtures', | ||
| 'cli', | ||
| 'mocks', | ||
| 'configs', | ||
| ); | ||
|
|
||
|
|
@@ -24,22 +20,13 @@ describe('coreConfigMiddleware', () => { | |
| skipPlugins: [], | ||
| }; | ||
|
|
||
| it.each(['ts', 'mjs', 'js'])( | ||
| 'should load a valid .%s config', | ||
| async extension => { | ||
| const config = await coreConfigMiddleware({ | ||
| config: path.join(configDirPath, `code-pushup.config.${extension}`), | ||
| ...CLI_DEFAULTS, | ||
| }); | ||
| expect(config.config).toContain(`code-pushup.config.${extension}`); | ||
| expect(config.upload?.project).toContain(extension); | ||
| }, | ||
| ); | ||
|
|
||
| it('should throw with invalid config path', async () => { | ||
| await expect( | ||
| coreConfigMiddleware({ config: 'wrong/path/to/config', ...CLI_DEFAULTS }), | ||
| ).rejects.toThrow(/File '.*' does not exist/); | ||
| it('should load a valid .%s config', async () => { | ||
| const config = await coreConfigMiddleware({ | ||
| config: path.join(configDirPath, `code-pushup.config.ts`), | ||
| ...CLI_DEFAULTS, | ||
| }); | ||
| expect(config.config).toContain(`code-pushup.config.ts`); | ||
| expect(config.upload?.project).toContain('ts'); | ||
|
Comment on lines
+23
to
+29
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test description still uses the |
||
| }); | ||
|
|
||
| it('should load config which relies on provided --tsconfig', async () => { | ||
|
|
@@ -54,16 +41,4 @@ describe('coreConfigMiddleware', () => { | |
| }), | ||
| ).resolves.toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should throw if --tsconfig is missing but needed to resolve import', async () => { | ||
| await expect( | ||
| coreConfigMiddleware({ | ||
| config: path.join( | ||
| configDirPath, | ||
| 'code-pushup.needs-tsconfig.config.ts', | ||
| ), | ||
| ...CLI_DEFAULTS, | ||
| }), | ||
| ).rejects.toThrow("Cannot find package '@example/custom-plugin'"); | ||
| }); | ||
| }); | ||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,24 @@ | ||
| const customPluginConfig = { | ||
| slug: 'good-feels', | ||
| title: 'Good feels', | ||
| icon: 'javascript', | ||
| audits: [ | ||
| { | ||
| slug: 'always-perfect', | ||
| title: 'Always perfect', | ||
| }, | ||
| ], | ||
| runner: () => [ | ||
| { | ||
| slug: 'always-perfect', | ||
| score: 1, | ||
| value: 100, | ||
| displayValue: '✅ Perfect! 👌', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export function customPlugin() { | ||
| return customPluginConfig; | ||
| } | ||
| export default customPluginConfig; |
File renamed without changes.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.