-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Accept a base URL and output URL objects
- Loading branch information
Showing
7 changed files
with
166 additions
and
99 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,45 @@ | ||
'use strict'; | ||
const { URL } = require('url'); | ||
|
||
expect.extend({ | ||
// This largely exists to work around https://github.com/nodejs/node/issues/24211. | ||
toMatchURL(received, expected) { | ||
if (!('href' in received) || typeof received.href !== 'string') { | ||
throw new Error(this.utils.matcherHint('[.not].toMatchURL', 'received', 'href') + | ||
'\n\n' + | ||
`Expected value to have a 'href' property that is a string. ` + | ||
`Received:\n` + | ||
` ${this.utils.printReceived(received)}\n` + | ||
(received ? `received.href:\n ${this.utils.printReceived(received.href)}` : '')); | ||
} | ||
|
||
received = received.href; | ||
expected = (new URL(expected)).href; | ||
|
||
const pass = received === expected; | ||
|
||
const message = pass ? | ||
() => { | ||
return this.utils.matcherHint('.not.toMatchURL') + | ||
'\n\n' + | ||
`Expected value to not match the URL (serialized):\n` + | ||
` ${this.utils.printExpected(expected)}\n` + | ||
`Received:\n` + | ||
` ${this.utils.printReceived(received)}`; | ||
} : | ||
() => { | ||
const diffString = this.utils.diff(expected, received, { | ||
expand: this.expand | ||
}); | ||
return this.utils.matcherHint('.toBe') + | ||
'\n\n' + | ||
`Expected value to be (using Object.is):\n` + | ||
` ${this.utils.printExpected(expected)}\n` + | ||
`Received:\n` + | ||
` ${this.utils.printReceived(received)}` + | ||
(diffString ? `\n\nDifference:\n\n${diffString}` : ''); | ||
}; | ||
|
||
return { message, pass }; | ||
} | ||
}); |
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,14 +1,14 @@ | ||
'use strict'; | ||
const { parseFromString } = require('../..'); | ||
|
||
exports.expectSpecifierMap = (input, output) => { | ||
expect(parseFromString(`{ "imports": ${input} }`)) | ||
exports.expectSpecifierMap = (input, baseURL, output) => { | ||
expect(parseFromString(`{ "imports": ${input} }`, baseURL)) | ||
.toEqual({ imports: output, scopes: {} }); | ||
|
||
expect(parseFromString(`{ "scopes": { "aScope": ${input} } }`)) | ||
expect(parseFromString(`{ "scopes": { "aScope": ${input} } }`, baseURL)) | ||
.toEqual({ imports: {}, scopes: { aScope: output } }); | ||
}; | ||
|
||
exports.expectBad = input => { | ||
expect(() => parseFromString(input)).toThrow(TypeError); | ||
exports.expectBad = (input, baseURL) => { | ||
expect(() => parseFromString(input, baseURL)).toThrow(TypeError); | ||
}; |
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
Oops, something went wrong.