Skip to content

Commit

Permalink
[Tests] use babel instead of NODE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Djerbetian authored and ljharb committed Mar 14, 2020
1 parent 1a3a128 commit efb5f07
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
10 changes: 9 additions & 1 deletion .babelrc
Expand Up @@ -3,7 +3,15 @@
"sourceMaps": "inline",
"env": {
"test": {
"plugins": [ "istanbul" ]
"plugins": [
"istanbul",
[ "module-resolver", { "root": [ "./src/" ] } ]
]
},
"testCompiled": {
"plugins": [
[ "module-resolver", { "root": [ "./lib/" ] } ]
]
}
}
}
9 changes: 5 additions & 4 deletions package.json
Expand Up @@ -22,13 +22,13 @@
"build": "babel --quiet --out-dir lib src",
"postbuild": "npm run copy-metafiles",
"copy-metafiles": "for DIR in memo-parser resolvers/node resolvers/webpack utils; do cp LICENSE .npmrc \"${DIR}/\"; done",
"watch": "npm run mocha -- --watch tests/src",
"watch": "npm run tests-only -- -- --watch",
"pretest": "linklocal",
"posttest": "eslint .",
"mocha": "cross-env BABEL_ENV=test NODE_PATH=./src nyc -s mocha -R dot --recursive -t 5s",
"tests-only": "npm run mocha tests/src",
"mocha": "nyc -s mocha",
"tests-only": "cross-env BABEL_ENV=test npm run mocha tests/src",
"test": "npm run tests-only",
"test-compiled": "npm run prepublish && NODE_PATH=./lib mocha --compilers js:babel-register --recursive tests/src",
"test-compiled": "npm run prepublish && BABEL_ENV=testCompiled mocha --compilers js:babel-register tests/src",
"test-all": "npm test && for resolver in ./resolvers/*; do cd $resolver && npm test && cd ../..; done",
"prepublish": "not-in-publish || npm run build",
"coveralls": "nyc report --reporter lcovonly && cat ./coverage/lcov.info | coveralls"
Expand Down Expand Up @@ -60,6 +60,7 @@
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-plugin-istanbul": "^4.1.6",
"babel-plugin-module-resolver": "^2.7.1",
"babel-preset-es2015-argon": "latest",
"babel-register": "^6.26.0",
"babylon": "^6.18.0",
Expand Down
3 changes: 3 additions & 0 deletions test/mocha.opts
@@ -0,0 +1,3 @@
--reporter=dot
--recursive
-t 5s
9 changes: 8 additions & 1 deletion tests/src/package.js
Expand Up @@ -51,10 +51,17 @@ describe('package', function () {
let preamble = 'import/'

for (let rule in module.configs[configFile].rules) {
expect(() => require('rules/'+rule.slice(preamble.length)))
expect(() => require(getRulePath(rule.slice(preamble.length))))
.not.to.throw(Error)
}
}

function getRulePath(ruleName) {
// 'require' does not work with dynamic paths because of the compilation step by babel
// (which resolves paths according to the root folder configuration)
// the usage of require.resolve on a static path gets around this
return path.resolve(require.resolve('rules/no-unresolved'), '..', ruleName)
}
})

it('marks deprecated rules in their metadata', function () {
Expand Down

0 comments on commit efb5f07

Please sign in to comment.