-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: decouple test from file system
- Loading branch information
Showing
17 changed files
with
263 additions
and
328 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
17 changes: 17 additions & 0 deletions
17
packages/cli/src/lib/commands/assert/utils/__snapshots__/md-report.unit.test.ts.snap
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,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`md-table should print MD table if getStepsTable is called with a reduced result 1`] = ` | ||
"| Step Name | Gather Mode | Performance | Accessibility | Best Practices | Seo | Pwa | | ||
| :----------------------------- | :---------: | :---------: | :-----------: | :------------: | :-: | :-: | | ||
| Navigation report (127.0.0.1/) | navigation | - | 100 | 92 | 100 | 30 | | ||
| Timespan report (127.0.0.1/) | timespan | 10/11 | - | 5/7 | - | - | | ||
| Snapshot report (127.0.0.1/) | snapshot | Ø 3/4 | 10/10 | 4/5 | 9/9 | - |" | ||
`; | ||
|
||
exports[`md-table should return a Md table comparing to reports if getStepsTable is passed a baseline report 1`] = ` | ||
"| Step Name | Gather Mode | Performance | Accessibility | Best Practices | Seo | Pwa | | ||
| :----------------------------- | :---------: | :---------: | :-----------: | :------------: | :------: | :------: | | ||
| Navigation report (127.0.0.1/) | navigation | - | 100 | 92 (-7) | 100 | 30 (+32) | | ||
| Timespan report (127.0.0.1/) | timespan | 10/11 | - | 5/7 | - | - | | ||
| Snapshot report (127.0.0.1/) | snapshot | Ø 3/4 | 10/10 (-1) | 4/5 | 9/9 (-1) | - |" | ||
`; |
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
96 changes: 0 additions & 96 deletions
96
packages/cli/src/lib/commands/collect/utils/user-flow/load-flow.test.ts
This file was deleted.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
packages/cli/src/lib/commands/collect/utils/user-flow/load-flow.ts
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
67 changes: 67 additions & 0 deletions
67
packages/cli/src/lib/commands/collect/utils/user-flow/load-flow.unit.test.ts
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,67 @@ | ||
import { loadFlow } from './load-flow'; | ||
import * as fileHelpers from '../../../../core/file'; | ||
import * as fs from 'node:fs'; | ||
|
||
jest.mock('node:fs'); | ||
jest.mock('../../../../core/file'); | ||
|
||
describe('loading user-flow scripts for execution', () => { | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}) | ||
|
||
it('should throw if ufPath does not exist', () => { | ||
const existsSyncSpy = jest.spyOn(fs, 'existsSync').mockReturnValue(false); | ||
expect(() => loadFlow({ ufPath: './path' })).toThrow(); | ||
expect(existsSyncSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw if ufPath points to a file and it does not end in with ts or js', () => { | ||
jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
jest.spyOn(fs, 'lstatSync').mockReturnValue({ isDirectory: () => false } as fs.Stats); | ||
const resolveAnyFileSpy = jest.spyOn(fileHelpers, 'resolveAnyFile'); | ||
expect(() => loadFlow({ ufPath: './path/file.json' })).toThrow(); | ||
expect(resolveAnyFileSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should throw if ufPath points to a directory and it does not contain any files that end with ts or js', () => { | ||
jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
jest.spyOn(fs, 'lstatSync').mockReturnValue({ isDirectory: () => true } as fs.Stats); | ||
jest.spyOn(fs, 'readdirSync').mockReturnValue(['file.json' as unknown as fs.Dirent]) | ||
const resolveAnyFileSpy = jest.spyOn(fileHelpers, 'resolveAnyFile'); | ||
expect(() => loadFlow({ ufPath: './path' })).toThrow(); | ||
expect(resolveAnyFileSpy).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should extract all file paths in the directory if ufPath points to a directory', () => { | ||
jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
jest.spyOn(fileHelpers, 'resolveAnyFile').mockReturnValue('Flow Dummy' as any); | ||
const isDirectorySpy = jest.spyOn(fs, 'lstatSync').mockReturnValue({ isDirectory: () => true } as fs.Stats); | ||
const readdirSyncSpy = jest.spyOn(fs, 'readdirSync').mockReturnValue(['file.ts' as unknown as fs.Dirent]) | ||
loadFlow({ ufPath: './user-flow-dir-path' }); | ||
expect(isDirectorySpy).toHaveBeenCalled(); | ||
expect(readdirSyncSpy).toHaveBeenCalledWith( | ||
expect.stringContaining('user-flow-dir-path') | ||
); | ||
}); | ||
|
||
it('should only resolve files ending in ts or js', () => { | ||
jest.spyOn(fs, 'existsSync').mockReturnValue(true); | ||
jest.spyOn(fs, 'lstatSync').mockReturnValue({ isDirectory: () => true } as fs.Stats); | ||
jest.spyOn(fs, 'readdirSync') | ||
.mockReturnValue(['file.ts', 'file.js', 'file.tsx', 'file.json', 'file.js.json'] as unknown as fs.Dirent[]); | ||
const resolveAnyFileSpy = jest.spyOn(fileHelpers, 'resolveAnyFile'); | ||
loadFlow({ ufPath: './path' }); | ||
expect(resolveAnyFileSpy).toHaveBeenCalledTimes(2); | ||
expect(resolveAnyFileSpy).toHaveBeenNthCalledWith( | ||
1, | ||
expect.stringContaining('file.ts') | ||
); | ||
expect(resolveAnyFileSpy).toHaveBeenNthCalledWith( | ||
2, | ||
expect.stringContaining('file.js') | ||
); | ||
}) | ||
}); | ||
|
70 changes: 0 additions & 70 deletions
70
packages/cli/src/lib/commands/init/processes/generate-lh-budgets.test.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.