Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the new "extensions" option in @babel/register
- Loading branch information
1 parent
d57bac4
commit c19499e
Showing
29 changed files
with
273 additions
and
13 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
3 changes: 3 additions & 0 deletions
3
packages/babel-register/test/fixtures/integration/default-extensions/babel.config.json
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,3 @@ | ||
{ | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.cjs
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 @@ | ||
console.log("DONE: foo.cjs"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.es
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 @@ | ||
console.log("DONE: foo.es"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.es6
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 @@ | ||
console.log("DONE: foo.es6"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.jsx
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 @@ | ||
console.log("DONE: foo.jsx"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.mjs
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 @@ | ||
console.log("DONE: foo.mjs"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.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 @@ | ||
console.log("DONE: foo.ts"); |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/default-extensions/foo.tsx
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 @@ | ||
console.log("DONE: foo.tsx"); |
11 changes: 11 additions & 0 deletions
11
packages/babel-register/test/fixtures/integration/default-extensions/index.js
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,11 @@ | ||
require("./foo.jsx"); | ||
require("./foo.es6"); | ||
require("./foo.es"); | ||
require("./foo.mjs"); | ||
|
||
// Not enabled by default | ||
require("./foo.ts"); | ||
require("./foo.tsx"); | ||
require("./foo.cjs"); | ||
|
||
console.log("DONE: index.js"); |
4 changes: 4 additions & 0 deletions
4
packages/babel-register/test/fixtures/integration/load-ts/babel.config.json
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,4 @@ | ||
{ | ||
"extensions": [".js", ".ts"], | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/load-ts/foo.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 @@ | ||
console.log("DONE: foo.ts"); |
3 changes: 3 additions & 0 deletions
3
packages/babel-register/test/fixtures/integration/load-ts/index.js
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,3 @@ | ||
require("./foo.ts"); | ||
|
||
console.log("DONE: index.js"); |
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,9 @@ | ||
module.exports = function () { | ||
return { | ||
pre() { | ||
console.log( | ||
`LOADED: ${JSON.stringify(this.filename.replace(__dirname, "<ROOT>"))}`, | ||
); | ||
}, | ||
}; | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/babel-register/test/fixtures/integration/no-load-ts/babel.config.json
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,4 @@ | ||
{ | ||
"extensions": [".js"], | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/no-load-ts/foo.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 @@ | ||
console.log("DONE: foo.ts"); |
3 changes: 3 additions & 0 deletions
3
packages/babel-register/test/fixtures/integration/no-load-ts/index.js
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,3 @@ | ||
require("./foo.ts"); | ||
|
||
console.log("DONE: index.js"); |
4 changes: 4 additions & 0 deletions
4
.../babel-register/test/fixtures/integration/resolve-extension-from-config/babel.config.json
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,4 @@ | ||
{ | ||
"extensions": [".js", ".ts"], | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/resolve-extension-from-config/foo.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 @@ | ||
console.log("DONE: foo.ts"); |
3 changes: 3 additions & 0 deletions
3
packages/babel-register/test/fixtures/integration/resolve-extension-from-config/index.js
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,3 @@ | ||
require("./foo"); // <-- No extensino here! | ||
|
||
console.log("DONE: index.js"); |
4 changes: 4 additions & 0 deletions
4
...bel-register/test/fixtures/integration/resolve-extension-from-main-file/babel.config.json
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,4 @@ | ||
{ | ||
"extensions": ["*"], | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-register/test/fixtures/integration/resolve-extension-from-main-file/foo.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 @@ | ||
console.log("DONE: foo.ts"); |
3 changes: 3 additions & 0 deletions
3
packages/babel-register/test/fixtures/integration/resolve-extension-from-main-file/index.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,3 @@ | ||
require("./foo"); // <-- No extensino here! | ||
|
||
console.log("DONE: index.ts"); |
4 changes: 4 additions & 0 deletions
4
...register/test/fixtures/integration/resolve-extension-from-required-file/babel.config.json
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,4 @@ | ||
{ | ||
"extensions": ["*"], | ||
"plugins": ["../logger"] | ||
} |
1 change: 1 addition & 0 deletions
1
...ages/babel-register/test/fixtures/integration/resolve-extension-from-required-file/bar.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 @@ | ||
console.log("DONE: bar.ts"); |
3 changes: 3 additions & 0 deletions
3
...ages/babel-register/test/fixtures/integration/resolve-extension-from-required-file/foo.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,3 @@ | ||
require("./bar"); // <-- no extension! | ||
|
||
console.log("DONE: foo.ts"); |
3 changes: 3 additions & 0 deletions
3
...es/babel-register/test/fixtures/integration/resolve-extension-from-required-file/index.js
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,3 @@ | ||
require("./foo.ts"); | ||
|
||
console.log("DONE: index.js"); |
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,113 @@ | ||
import { exec as execCb } from "child_process"; | ||
|
||
// TODO(Babel 8): Use util.promisify(execCb) | ||
const exec = (...args) => | ||
new Promise((resolve, reject) => { | ||
execCb(...args, (error, stdout, stderr) => { | ||
if (error) reject(error); | ||
else resolve({ stdout, stderr }); | ||
}); | ||
}); | ||
|
||
function fixture(name, file = "index.js") { | ||
const cwd = `${__dirname}/fixtures/integration/${name}`; | ||
return exec(`node -r ${__dirname}/.. ${cwd}/${file}`, { | ||
cwd, | ||
env: { ...process.env, BABEL_DISABLE_CACHE: true }, | ||
}); | ||
} | ||
|
||
describe("integration tests", function () { | ||
it("can hook into extensions defined by the config", async () => { | ||
const { stdout, stderr } = await fixture("load-ts"); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/load-ts/index.js\\" | ||
LOADED: \\"<ROOT>/load-ts/foo.ts\\" | ||
DONE: foo.ts | ||
DONE: index.js | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("does not hook into unknown extensions", async () => { | ||
const { stdout, stderr } = await fixture("no-load-ts"); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/no-load-ts/index.js\\" | ||
DONE: foo.ts | ||
DONE: index.js | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("hooks into the default extensions", async () => { | ||
const { stdout, stderr } = await fixture("default-extensions"); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/default-extensions/index.js\\" | ||
LOADED: \\"<ROOT>/default-extensions/foo.jsx\\" | ||
DONE: foo.jsx | ||
LOADED: \\"<ROOT>/default-extensions/foo.es6\\" | ||
DONE: foo.es6 | ||
LOADED: \\"<ROOT>/default-extensions/foo.es\\" | ||
DONE: foo.es | ||
LOADED: \\"<ROOT>/default-extensions/foo.mjs\\" | ||
DONE: foo.mjs | ||
DONE: foo.ts | ||
DONE: foo.tsx | ||
DONE: foo.cjs | ||
DONE: index.js | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("node resolves extensions that it gets from the Babel config", async () => { | ||
const { stdout, stderr } = await fixture("resolve-extension-from-config"); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/resolve-extension-from-config/index.js\\" | ||
LOADED: \\"<ROOT>/resolve-extension-from-config/foo.ts\\" | ||
DONE: foo.ts | ||
DONE: index.js | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("node resolves extensions that it gets from the main file", async () => { | ||
const { stdout, stderr } = await fixture( | ||
"resolve-extension-from-main-file", | ||
"index.ts", | ||
); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/resolve-extension-from-main-file/index.ts\\" | ||
LOADED: \\"<ROOT>/resolve-extension-from-main-file/foo.ts\\" | ||
DONE: foo.ts | ||
DONE: index.ts | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
|
||
it("node resolves extensions that it gets from a required file", async () => { | ||
const { stdout, stderr } = await fixture( | ||
"resolve-extension-from-required-file", | ||
); | ||
|
||
expect(stdout).toMatchInlineSnapshot(` | ||
"LOADED: \\"<ROOT>/resolve-extension-from-required-file/index.js\\" | ||
LOADED: \\"<ROOT>/resolve-extension-from-required-file/foo.ts\\" | ||
LOADED: \\"<ROOT>/resolve-extension-from-required-file/bar.ts\\" | ||
DONE: bar.ts | ||
DONE: foo.ts | ||
DONE: index.js | ||
" | ||
`); | ||
expect(stderr).toMatchInlineSnapshot(`""`); | ||
}); | ||
}); |