-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #737 from chromaui/trace-diagnostics-update
- Loading branch information
Showing
4 changed files
with
94 additions
and
19 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 |
---|---|---|
@@ -1,18 +1,58 @@ | ||
import mockfs from 'mock-fs'; | ||
import chalk from 'chalk'; | ||
import { execSync } from 'child_process'; | ||
|
||
// eslint-disable-next-line jest/no-mocks-import | ||
import * as trimmedFile from './__mocks__/previewStatsJson/preview-stats.trimmed.json'; | ||
import { | ||
rootDirNote, | ||
baseDirNote, | ||
storybookDirNote, | ||
traceSuggestions, | ||
} from './ui/messages/info/tracedAffectedFiles'; | ||
|
||
mockfs({ | ||
'./storybook-static/preview-stats.json': JSON.stringify(trimmedFile), | ||
}); | ||
const scriptCommand = `$ ./bin/main.cjs trace ./bin-src/ui/messages/errors/invalidReportPath.ts`; | ||
|
||
afterEach(() => { | ||
mockfs.restore(); | ||
}); | ||
describe('Test trace script from package.json', () => { | ||
it('returns the default output successfully', () => { | ||
const scriptName = | ||
'chromatic trace ./bin-src/ui/messages/errors/invalidReportPath.ts -s bin-src/__mocks__/previewStatsJson/preview-stats.trimmed.json'; | ||
|
||
// Execute the script as a child process | ||
const output = execSync(`yarn ${scriptName}`).toString().trim(); | ||
|
||
// Add your assertions based on the expected output or behavior of the script | ||
expect(output).toContain(scriptCommand); | ||
|
||
// Verify that the output does not contain the expanded output | ||
expect(output).not.toContain(rootDirNote); | ||
}); | ||
it('outputs directory info when -m expanded is passed', () => { | ||
const scriptName = | ||
'chromatic trace ./bin-src/ui/messages/errors/invalidReportPath.ts -s bin-src/__mocks__/previewStatsJson/preview-stats.trimmed.json -m expanded'; | ||
|
||
// Execute the script as a child process | ||
const output = execSync(`yarn ${scriptName}`).toString().trim(); | ||
|
||
const expandedStoryModule = `bin-src/ui/messages/errors/invalidReportPath.stories.ts`; | ||
const expandedFileModule = `bin-src/ui/messages/errors/invalidReportPath.ts`; | ||
|
||
// Add your assertions based on the expected output or behavior of the script | ||
expect(output).toContain(rootDirNote); | ||
expect(output).toContain(baseDirNote); | ||
expect(output).toContain(storybookDirNote); | ||
expect(output).toContain(traceSuggestions); | ||
expect(output).toContain(expandedStoryModule); | ||
expect(output).toContain(expandedFileModule); | ||
}); | ||
it('outputs untraced info when --mode expanded is passed with -u and an untraced file', () => { | ||
const scriptName = | ||
'chromatic trace ./bin-src/ui/messages/errors/invalidReportPath.ts -s bin-src/__mocks__/previewStatsJson/preview-stats.trimmed.json -m expanded -u ./bin-src/ui/messages/errors/invalidReportPath.ts'; | ||
|
||
// Execute the script as a child process | ||
const output = execSync(`yarn ${scriptName}`).toString().trim(); | ||
|
||
const untracedFile = `./bin-src/ui/messages/errors/invalidReportPath.ts`; | ||
const untracedFileNote = `We detected some untraced files`; | ||
|
||
describe('Trace', () => { | ||
it('acts as a placeholder for a trace test', async () => { | ||
expect(true).toBe(true); | ||
expect(output).toContain(untracedFileNote); | ||
expect(output).toContain(untracedFile); | ||
}); | ||
}); |
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