Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade core-js to version 3 (#25595)
- Loading branch information
Showing
20 changed files
with
551 additions
and
376 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
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
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
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
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
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
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
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
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
75 changes: 75 additions & 0 deletions
75
packages/gatsby/src/utils/webpack/__tests__/corejs-resolver.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,75 @@ | ||
import { slash } from "gatsby-core-utils" | ||
import { CoreJSResolver } from "../corejs-resolver" | ||
|
||
function executeResolve( | ||
resolver: CoreJSResolver, | ||
request: { request: string }, | ||
doResolveMock: unknown | ||
): Promise<string> { | ||
return new Promise((resolve, reject) => { | ||
const webpackResolver = { | ||
doResolve: doResolveMock, | ||
ensureHook: (hook: string): string => hook, | ||
getHook: (): Record<string, unknown> => { | ||
return { | ||
tapAsync: (_name: string, fn: Function): void => { | ||
fn(request, null, (err, result) => | ||
err ? reject(err) : resolve(result) | ||
) | ||
}, | ||
} | ||
}, | ||
} | ||
|
||
resolver.apply(webpackResolver) | ||
}) | ||
} | ||
|
||
describe(`CoreJSResolver`, () => { | ||
it(`should convert core-js@2 file to core-js@3`, async () => { | ||
const resolver = new CoreJSResolver() | ||
|
||
const doResolve = jest.fn((_, request, __, ___, callback) => | ||
callback(null, slash(request.request)) | ||
) | ||
|
||
expect( | ||
await executeResolve( | ||
resolver, | ||
{ request: `core-js/modules/es6.array.split.js` }, | ||
doResolve | ||
) | ||
).toEqual(expect.stringContaining(`core-js/modules/es.array.split.js`)) | ||
}) | ||
|
||
it(`should convert es6.regexp.replace to it's corejs@3 equivalent`, async () => { | ||
const resolver = new CoreJSResolver() | ||
|
||
const doResolve = jest.fn((_, request, __, ___, callback) => | ||
callback(null, slash(request.request)) | ||
) | ||
|
||
expect( | ||
await executeResolve( | ||
resolver, | ||
{ request: `core-js/modules/es6.regexp.replace.js` }, | ||
doResolve | ||
) | ||
).toEqual(expect.stringContaining(`core-js/modules/es.string.replace.js`)) | ||
}) | ||
|
||
it(`should ignore non corejs requests`, async () => { | ||
const resolver = new CoreJSResolver() | ||
|
||
const doResolve = jest.fn() | ||
|
||
expect( | ||
await executeResolve( | ||
resolver, | ||
{ request: `gatsby/not/core-js.js` }, | ||
doResolve | ||
) | ||
).toBeUndefined() | ||
expect(doResolve).not.toHaveBeenCalled() | ||
}) | ||
}) |
Oops, something went wrong.