运行 通过 shell 脚本包装器对 Node 模块进行伊斯坦布尔测试
Running Istanbul test coverage for Node modules via shell script wrappers
我的 package.json 中的脚本目前看起来像这样:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "istanbul cover jasmine-node spec",
"start": "gulp"
}
测试脚本运行这个.sh文件:
#!/bin/sh
echo "Renaming database file produced by previous test run"
mv -f 'shared-local-instance.db' 'shared-local-instance.db.previous'
echo "Starting DynamoDB"
java -Djava.library.path=./DynamoDBLocal_lib -jar dynamodb/DynamoDBLocal.jar -sharedDb &
export JAVA_PID=$!
echo "Running Tests"
./node_modules/jasmine-node/bin/jasmine-node spec
echo "Cleaning up DynamoDB - killing local instance"
kill -9 $JAVA_PID
但是我现在想将我的 coverage
脚本更改为 运行 shell 文件:
"coverage": "istanbul cover ./spec/run-local-tests.sh"
但我随后收到一条错误消息:
echo "Renaming database file produced by previous test run"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
有什么方法可以让我的 shell 文件变成 运行?
RTFM.
伊斯坦布尔文档说:
The cover
command can be used to get a coverage object and reports for any arbitrary node script.
(强调我的)
istanbul cover
需要节点脚本。它无法覆盖 shell 脚本或任何其他任意可执行文件。
您可以编写一个 shell 脚本来执行您需要的任何操作 setup/cleanup,然后启动 istanbul cover
,然后这样配置它:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "./spec/run-local-tests-with-coverage.sh",
"start": "gulp"
}
或者您可以修改现有的脚本,也许像这样:
echo "Running Tests"
${COVERAGE} ./node_modules/jasmine-node/bin/jasmine-node spec
然后设置环境变量调用:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "env COVERAGE='istanbul coverage' ./spec/run-local-tests.sh",
"start": "gulp"
}
我的 package.json 中的脚本目前看起来像这样:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "istanbul cover jasmine-node spec",
"start": "gulp"
}
测试脚本运行这个.sh文件:
#!/bin/sh
echo "Renaming database file produced by previous test run"
mv -f 'shared-local-instance.db' 'shared-local-instance.db.previous'
echo "Starting DynamoDB"
java -Djava.library.path=./DynamoDBLocal_lib -jar dynamodb/DynamoDBLocal.jar -sharedDb &
export JAVA_PID=$!
echo "Running Tests"
./node_modules/jasmine-node/bin/jasmine-node spec
echo "Cleaning up DynamoDB - killing local instance"
kill -9 $JAVA_PID
但是我现在想将我的 coverage
脚本更改为 运行 shell 文件:
"coverage": "istanbul cover ./spec/run-local-tests.sh"
但我随后收到一条错误消息:
echo "Renaming database file produced by previous test run"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected string
有什么方法可以让我的 shell 文件变成 运行?
RTFM.
伊斯坦布尔文档说:
The
cover
command can be used to get a coverage object and reports for any arbitrary node script.
(强调我的)
istanbul cover
需要节点脚本。它无法覆盖 shell 脚本或任何其他任意可执行文件。
您可以编写一个 shell 脚本来执行您需要的任何操作 setup/cleanup,然后启动 istanbul cover
,然后这样配置它:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "./spec/run-local-tests-with-coverage.sh",
"start": "gulp"
}
或者您可以修改现有的脚本,也许像这样:
echo "Running Tests"
${COVERAGE} ./node_modules/jasmine-node/bin/jasmine-node spec
然后设置环境变量调用:
"scripts": {
"test": "./spec/run-local-tests.sh",
"coverage": "env COVERAGE='istanbul coverage' ./spec/run-local-tests.sh",
"start": "gulp"
}