문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판이전 판다음 판 | 이전 판 | ||
| study:script_test [2019/06/29 03:56] – [Links] taekgu | study:script_test [2025/04/15 10:05] (현재) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| 줄 2: | 줄 2: | ||
| ===== webpack + karma + jasmine ===== | ===== webpack + karma + jasmine ===== | ||
| - | [[https:// | + | |
| + | [[https:// | ||
| 제안하는 package: | 제안하는 package: | ||
| 줄 17: | 줄 18: | ||
| npm install --save-dev karma-jasmine karma-jasmine-html-reporter karma-mocha-reporter karma-webpack | npm install --save-dev karma-jasmine karma-jasmine-html-reporter karma-mocha-reporter karma-webpack | ||
| </ | </ | ||
| + | |||
| + | // 여기는 Tama가 추가 // | ||
| + | | ||
| + | npm install --save-dev @types/ | ||
| + | ** 기타 로더들 ** | ||
| + | * babel-loader | ||
| + | * css-loader | ||
| + | * style-loader | ||
| + | * ts-loader | ||
| + | |||
| ==== 2.karma.conf.js파일 생성 ==== | ==== 2.karma.conf.js파일 생성 ==== | ||
| '' | '' | ||
| 줄 185: | 줄 196: | ||
| * [[https:// | * [[https:// | ||
| ===== karma ===== | ===== karma ===== | ||
| - | ==== karma.conf.js ==== | + | |
| - | * frameworks는 테스트 프레임워크 이름를 설정하는데 '' | + | [[http:// |
| - | * files는 테스트와 테스트 대상이 되는 파일, 그리고 필요하면 제이쿼리같은 써드파티 라이브러리등 테스트에 필요한 파일 목록을 나열한다. 나는 src 폴더에는 소스코드, | + | |
| - | * browsers는 테스트할 브라우저를 기술한다.카르마는 크롬(Chrome), | + | |
| - | * autoWatch는 테스트 종료후 계속 파일 변화를 감지하면서 테스트를 자동으로 재실행하는 옵션이다. 모카의 –watch 옵션과 같은 기능이다. | + | ==== karma.conf.js의 구성==== |
| + | | ||
| + | * **frameworks**는 테스트 프레임워크 이름를 설정하는데 '' | ||
| + | | ||
| + | | ||
| + | | ||
| ==== files ==== | ==== files ==== | ||
| files배열은 브라우저에 포함된 파일과 karma가 보고, 제공하는 파일을 결정합니다. | files배열은 브라우저에 포함된 파일과 karma가 보고, 제공하는 파일을 결정합니다. | ||
| 줄 211: | 줄 227: | ||
| // this file will be served on demand from disk and will be ignored by the watcher | // this file will be served on demand from disk and will be ignored by the watcher | ||
| - | {pattern: ' | + | {pattern: ' |
| + | {pattern: ' | ||
| + | {pattern: ' | ||
| + | {pattern: ' | ||
| + | / | ||
| + | watched: if autoWatch is true all files that have watched set to true will be watched for changes | ||
| + | served: should the files be served by Karma' | ||
| + | included: should the files be included in the browser using < | ||
| + | nocache: should the files be served from disk on each request by Karma' | ||
| + | /*assets: | ||
| + | {pattern: ' | ||
| + | {pattern: ' | ||
| ], | ], | ||
| </ | </ | ||
| - | ==== 추가 | + | ==== 추가 |
| - | 생성한 카르마 컴피그 파일로 카르마를 실행하려면 세 가지 카르마 플러그인을 추가 다운로드 해야한다. | + | |
| karma-jasmine: | karma-jasmine: | ||
| jasmine-core: | jasmine-core: | ||
| karma-chrome-launcher: | karma-chrome-launcher: | ||
| - | <code bash> | ||
| - | npm install karma-jasmine jasmine-core karma-chrome-launcher --save-dev | ||
| - | </ | ||
| - | ==== Install ==== | ||
| - | Now that we have gotten the why? out of the way, let’s see how we can go about implementing our own testing framework: | ||
| - | First and foremost, we’ll have to install the libraries that we wish to use to test our systems. | + | ==== mamajs의 karma.conf.js ==== |
| - | <code bash> | + | |
| - | npm install --save-dev mocha chai | + | |
| - | npm install --save-dev ts-node typescript | + | |
| - | npm install --save-dev @types/chai @types/ | + | |
| - | </ | + | |
| - | package.json | + | <code javascript |
| - | <code javascript> | + | // Karma configuration |
| - | " | + | // Generated on Mon Jun 03 2019 23:19:22 GMT+0900 (대한민국 표준시) |
| - | | + | const path = require(' |
| - | }, | + | var webpackConfig = require(' |
| - | </code> | + | |
| - | **Gulp** | + | module.exports = function(config) |
| - | We need to install two more packages | + | config.set({ |
| - | <code bash> | + | |
| - | npm install gulp gulp-mocha --save-dev | + | |
| + | basePath: '', | ||
| + | |||
| + | |||
| + | // frameworks to use | ||
| + | // available frameworks: https:// | ||
| + | frameworks: [' | ||
| + | |||
| + | | ||
| + | files: [ | ||
| + | {pattern: 'src/ | ||
| + | | ||
| + | | ||
| + | / | ||
| + | watched: if autoWatch is true all files that have watched set to true will be watched for changes | ||
| + | served: should the files be served by Karma' | ||
| + | included: should the files be included in the browser using <script> tag? | ||
| + | | ||
| + | /*assets: | ||
| + | {pattern: '*.html', | ||
| + | {pattern: ' | ||
| + | ], | ||
| + | |||
| + | // list of files / patterns | ||
| + | exclude: [ ], | ||
| + | |||
| + | // start these browsers | ||
| + | // available browser launchers: https:// | ||
| + | browsers: [' | ||
| + | |||
| + | // enable / disable watching file and executing tests whenever any file changes | ||
| + | autoWatch: true, | ||
| + | |||
| + | client: { | ||
| + | //capture all console output and pipe it to the terminal, true is default | ||
| + | captureConsole: | ||
| + | //if true, Karma clears the context window upon the completion of running the tests, true is default | ||
| + | clearContext: | ||
| + | //run the tests on the same window as the client, without using iframe or a new window, false is default | ||
| + | runInParent: | ||
| + | //true: runs the tests inside an iFrame; false: runs the tests in a new window, true is default | ||
| + | useIframe: | ||
| + | jasmine:{ | ||
| + | //tells jasmine | ||
| + | random: false | ||
| + | } | ||
| + | }, | ||
| + | // 여기부터 기본 init에서 수정 사항 | ||
| + | // 웹팩 설정 가져오기?? | ||
| + | webpack: { | ||
| + | mode: ' | ||
| + | //module: webpackConfig.module, | ||
| + | resolve: webpackConfig.resolve, | ||
| + | module: { | ||
| + | rules: [ | ||
| + | { | ||
| + | test: / | ||
| + | include: [ | ||
| + | path.resolve(__dirname, | ||
| + | ], | ||
| + | exclude: [/ | ||
| + | | ||
| + | | ||
| + | | ||
| + | presets: [' | ||
| + | // plugins: [' | ||
| + | } | ||
| + | } | ||
| + | }, | ||
| + | { | ||
| + | test: / | ||
| + | include: [ | ||
| + | path.resolve(__dirname, | ||
| + | ], | ||
| + | exclude: [/ | ||
| + | use: { | ||
| + | loader: ' | ||
| + | } | ||
| + | }, | ||
| + | { | ||
| + | test: / | ||
| + | use: [' | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | }, | ||
| + | |||
| + | // preprocess matching files before serving them to the browser | ||
| + | // available preprocessors: | ||
| + | preprocessors: | ||
| + | ' | ||
| + | ' | ||
| + | }, | ||
| + | |||
| + | // test results reporter to use | ||
| + | // possible values: ' | ||
| + | // available reporters: https:// | ||
| + | reporters: [' | ||
| + | |||
| + | |||
| + | // web server port | ||
| + | port: 9876, | ||
| + | |||
| + | |||
| + | // enable / disable colors in the output (reporters and logs) | ||
| + | colors: true, | ||
| + | |||
| + | |||
| + | // level of logging | ||
| + | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
| + | //logLevel: config.LOG_INFO, | ||
| + | logLevel: config.LOG_ERROR, | ||
| + | |||
| + | // Continuous Integration mode | ||
| + | // if true, Karma captures browsers, runs the tests and exits | ||
| + | singleRun: false, | ||
| + | |||
| + | // Concurrency level | ||
| + | // how many browser should be started simultaneous | ||
| + | concurrency: | ||
| + | }) | ||
| + | } | ||
| </ | </ | ||
| - | ==== Script Test ==== | ||
| - | * Mocha / Chai | ||
| - | * Jasmine | ||
| - | * [[https:// | ||
| ===== Jasmine ===== | ===== Jasmine ===== | ||
| ** Behavior-Driven JavaScript ** | ** Behavior-Driven JavaScript ** | ||