Skip to content

Commit

Permalink
refactor: add createLogger to makeChainWalker
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 15, 2020
1 parent a35a59e commit 56516c5
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 131 deletions.
114 changes: 41 additions & 73 deletions packages/babel-cli/test/fixtures/babel/--show-config/stdout.txt
@@ -1,77 +1,45 @@
programmatic options from @babel/cli
[
{
"sourceFileName": "stdin",
"presets": [
"/Users/jh/code/babel/packages/babel-preset-react"
],
"plugins": [
"/Users/jh/code/babel/packages/babel-plugin-transform-arrow-functions",
"/Users/jh/code/babel/packages/babel-plugin-transform-strict-mode",
"/Users/jh/code/babel/packages/babel-plugin-transform-modules-commonjs"
],
"configFile": "./my-config.js",
"showConfig": true,
"caller": {
"name": "@babel/cli"
},
"filename": "./src/index.js"
}
]
{
"sourceFileName": "stdin",
"presets": [
"<ROOTDIR>/packages/babel-preset-react"
],
"plugins": [
"<ROOTDIR>/packages/babel-plugin-transform-arrow-functions",
"<ROOTDIR>/packages/babel-plugin-transform-strict-mode",
"<ROOTDIR>/packages/babel-plugin-transform-modules-commonjs"
],
"configFile": "./my-config.js",
"showConfig": true,
"caller": {
"name": "@babel/cli"
},
"filename": "./src/index.js"
}

config <CWD>/my-config.js
[
{
"babelrc": false,
"plugins": [
null
],
"overrides": [
{
"test": "src/index.js",
"plugins": [
"@foo/babel-plugin-2",
{
"noDocumentAll": true
}
]
}
],
"env": {
"test": {
"plugins": [
[
"@foo/babel-plugin-3",
{
"noDocumentAll": true
}
]
]
},
"development": {
"plugins": [
"@foo/babel-plugin-4"
]
}
{
"babelrc": false,
"plugins": [
null
]
}

config <CWD>/my-config.js .env["test"]
{
"babelrc": false,
"plugins": [
null
]
}

config <CWD>/my-config.js .overrides[0]
{
"test": "src/index.js",
"plugins": [
"@foo/babel-plugin-2",
{
"noDocumentAll": true
}
},
{
"plugins": [
[
"@foo/babel-plugin-3",
{
"noDocumentAll": true
}
]
]
},
{
"test": "src/index.js",
"plugins": [
"@foo/babel-plugin-2",
{
"noDocumentAll": true
}
]
}
]
]
}
17 changes: 9 additions & 8 deletions packages/babel-cli/test/index.js
Expand Up @@ -9,6 +9,7 @@ const fs = require("fs");

const fixtureLoc = path.join(__dirname, "fixtures");
const tmpLoc = path.join(__dirname, "tmp");
const rootDir = path.resolve(__dirname, "../../..");

const fileFilter = function (x) {
return x !== ".DS_Store";
Expand All @@ -19,12 +20,12 @@ const outputFileSync = function (filePath, data) {
fs.writeFileSync(filePath, data);
};

const presetLocs = [path.join(__dirname, "../../babel-preset-react")];
const presetLocs = [path.join(rootDir, "./packages/babel-preset-react")];

const pluginLocs = [
path.join(__dirname, "/../../babel-plugin-transform-arrow-functions"),
path.join(__dirname, "/../../babel-plugin-transform-strict-mode"),
path.join(__dirname, "/../../babel-plugin-transform-modules-commonjs"),
path.join(rootDir, "./packages/babel-plugin-transform-arrow-functions"),
path.join(rootDir, "./packages/babel-plugin-transform-strict-mode"),
path.join(rootDir, "./packages/babel-plugin-transform-modules-commonjs"),
].join(",");

const readDir = function (loc, filter) {
Expand All @@ -49,19 +50,19 @@ const saveInFiles = function (files) {
});
};

const normalizeOutput = function (str, cwd) {
const normalizeOutput = function (str, cwd, root) {
let prev;
do {
prev = str;
str = str.replace(cwd, "<CWD>");
str = str.replace(cwd, "<CWD>").replace(root, "<ROOTDIR>");
} while (str !== prev);

return str.replace(/\(\d+ms\)/g, "(123ms)");
};

const assertTest = function (stdout, stderr, opts, cwd) {
stdout = normalizeOutput(stdout, cwd);
stderr = normalizeOutput(stderr, cwd);
stdout = normalizeOutput(stdout, cwd, rootDir);
stderr = normalizeOutput(stderr, cwd, rootDir);

const expectStderr = opts.stderr.trim();
stderr = stderr.trim();
Expand Down

0 comments on commit 56516c5

Please sign in to comment.