Skip to content

Commit

Permalink
test: improve failure message for the Babel plugin (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
silvenon authored Sep 29, 2020
1 parent 1fb7d8a commit 3150c46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-plugin-orbit-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"scripts": {
"generateTestFile": "node scripts/generateImports.js",
"build": "babel __fixtures__/index.js --out-file dist/index.js --root-mode upward",
"test": "yarn generateTestFile && yarn build && node dist/index.js"
"test": "yarn generateTestFile && yarn build && node scripts/testRequire.js"
}
}
19 changes: 19 additions & 0 deletions packages/babel-plugin-orbit-components/scripts/testRequire.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @noflow

// to avoid an ESLint issue with --report-unused-disable-directives
const path = "../dist";

try {
// eslint-disable-next-line global-require, import/no-dynamic-require
require(path);
} catch (err) {
const match = err.message.match(/Cannot find module '([^']*\/(\w+))'/);
if (match) {
console.error(
`\n@kiwicom/babel-plugin-orbit-components did not correctly transform the import path for the module "${match[2]}", "${match[1]}" doesn't exist. Make sure to configure it properly.\n`,
);
} else {
console.error(err);
}
process.exit(1);
}

0 comments on commit 3150c46

Please sign in to comment.