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

fix(message-utils): convert URLs to paths #12277

Merged
merged 7 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

### Fixes

- `[matcher-utils]` Correct diff for expected asymmetric matchers (#12264)[https://github.com/facebook/jest/pull/12264]
- `[expect]` Add a fix for `.toHaveProperty('')` ([#12251](https://github.com/facebook/jest/pull/12251))
- `[jest-environment-node]` Add `atob` and `btoa` ([#12269](https://github.com/facebook/jest/pull/12269))
- `[jest-message-util]` Fix `.getTopFrame()` (and `toMatchInlineSnapshot()`) with `mjs` files ([#12277](https://github.com/facebook/jest/pull/12277))
- `[matcher-utils]` Correct diff for expected asymmetric matchers ([#12264](https://github.com/facebook/jest/pull/12264))

### Chore & Maintenance

Expand Down
8 changes: 7 additions & 1 deletion packages/jest-message-util/src/__tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import {readFileSync} from 'graceful-fs';
import slash = require('slash');
import tempy = require('tempy');
import {formatExecError, formatResultsErrors, formatStackTrace} from '..';
import {formatExecError, formatResultsErrors, formatStackTrace, getTopFrame} from '..';

const rootDir = tempy.directory();

Expand Down Expand Up @@ -365,3 +365,9 @@ describe('formatStackTrace', () => {
expect(message).toMatchSnapshot();
});
});

it('getTopFrame should return a path for mjs files', () => {
const frame = getTopFrame([' at stack (file:///Users/user/project/inline.mjs:1:1)']);

expect(frame.file).toBe('/Users/user/project/inline.mjs');
});
4 changes: 4 additions & 0 deletions packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import slash = require('slash');
import StackUtils = require('stack-utils');
import type {Config, TestResult} from '@jest/types';
import {format as prettyFormat} from 'pretty-format';
import {fileURLToPath} from 'url';
import type {Frame} from './types';

export type {Frame} from './types';
Expand Down Expand Up @@ -273,6 +274,9 @@ export const getTopFrame = (lines: Array<string>): Frame | null => {
const parsedFrame = stackUtils.parseLine(line.trim());

if (parsedFrame && parsedFrame.file) {
if (parsedFrame.file.startsWith('file://')) {
parsedFrame.file = fileURLToPath(parsedFrame.file);
mshima marked this conversation as resolved.
Show resolved Hide resolved
}
return parsedFrame as Frame;
}
}
Expand Down