문제

i 테스트를 실행하려면 mocha 명령을 실행합니다

$ ./node_modules/.bin/mocha --compilers coffee:coffee-script -R spec
.

커피 스크립트 컴파일러에 추가 옵션을 전달하고자합니다 (--bare to .js를 컴파일 할 때 도입 된 외부 폐쇄를 피하기 위해).이것을 할 수있는 방법이 있습니까?나는

을 시도했다
$ ./node_modules/.bin/mocha --compilers coffee:coffee-script --bare -R spec
.

하지만 그것은 옳지 않습니다.또한 --bare가 모카에 대한 유효한 옵션이 아니라는 것을 실패했습니다.

  error: unknown option `--bare'
.

도움이 되었습니까?

해결책

--compiler 옵션은이 기능을 지원하지 않지만 옵션으로 컴파일러를 활성화 한 다음 Mocha의 --Require 옵션을 사용하여 등록 스크립트를 활성화 할 수 있습니다.예를 들어, babelhook.js라는 프로젝트의 루트에 파일을 만듭니다.

// This file is required in mocha.opts
// The only purpose of this file is to ensure
// the babel transpiler is activated prior to any
// test code, and using the same babel options

require("babel-register")({
  experimental: true
});
.

을 mocha.opts에 추가하십시오.

--require babelhook
.

그리고 그게 다야합니다.모카는 시험 전에 babelhook.js가 필요합니다.

다른 팁

루트에 .babelrc 파일을 추가하기 만하면됩니다. 그런 다음 Babel (Build, Runtime, Testet 등)의 인스턴스는 참조됩니다. https://babeljs.io/docs/usage/babelrc/

환경별로 특정 구성 옵션을 추가 할 수도 있습니다.

누군가가 이것에 걸리는 경우를 대비하여.바벨의 '실험'옵션이 더 이상 사용되지 않습니다.'babelhook.js'를 읽어야합니다.

// This file is required in mocha.opts
// The only purpose of this file is to ensure
// the babel transpiler is activated prior to any
// test code, and using the same babel options

require("babel/register")({
  stage: 1
});
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top