"Node.js"의 두 판 사이의 차이
잔글 (→Test Framework) |
잔글 (→Package 관리) |
||
32번째 줄: | 32번째 줄: | ||
== Package 관리 == | == Package 관리 == | ||
+ | |||
+ | * npm init : 패키지 관리 설정 파일인 package.json 파일을 생성 한다. | ||
+ | * npm install [모듈명] --save : 모듈을 설치하고 package.json 파일에 반영 한다. | ||
+ | |||
+ | mkdir -p /work/appl/modbus | ||
+ | cd /work/appl/modbus | ||
+ | npm init | ||
+ | #--- scada_modbus, 0.0.1, Modbus for SCADA, scada.js, 엔터, 엔터, 엔터, OBCon, 엔터, yes | ||
+ | This utility will walk you through creating a package.json file. | ||
+ | It only covers the most common items, and tries to guess sensible defaults. | ||
+ | |||
+ | See `npm help json` for definitive documentation on these fields | ||
+ | and exactly what they do. | ||
+ | |||
+ | Use `npm install <pkg> --save` afterwards to install a package and | ||
+ | save it as a dependency in the package.json file. | ||
+ | |||
+ | Press ^C at any time to quit. | ||
+ | name: (modbus) scada_modbus | ||
+ | version: (1.0.0) 0.0.1 | ||
+ | description: Modbus for SCADA | ||
+ | entry point: (index.js) scada.js | ||
+ | test command: | ||
+ | git repository: | ||
+ | keywords: | ||
+ | author: OBCon | ||
+ | license: (ISC) | ||
+ | About to write to /work/appl/modbus/package.json: | ||
+ | |||
+ | { | ||
+ | "name": "scada_modbus", | ||
+ | "version": "0.0.1", | ||
+ | "description": "Modbus for SCADA", | ||
+ | "main": "scada.js", | ||
+ | "scripts": { | ||
+ | "test": "echo \"Error: no test specified\" && exit 1" | ||
+ | }, | ||
+ | "author": "OBCon", | ||
+ | "license": "ISC" | ||
+ | } | ||
+ | Is this ok? (yes) yes | ||
+ | |||
+ | # npm install [모듈명] --save #--- 모듈 설치후 package.json 파일에 추가 | ||
+ | npm install jsmodbus --save #--- 3.1.0 | ||
+ | npm install mocha --save #--- 5.2.0 | ||
+ | npm install sinon --save #--- 6.3.3 | ||
== Test Framework == | == Test Framework == |
2018년 9월 17일 (월) 17:59 판
Server Side JavaScript인 Node.js를 정리 합니다.
- 홈페이지 : http://nodejs.org/
- 다운로드 : http://nodejs.org/download/
- 라이선스 :
- 플랫폼 : JavaScript
목차
Node.js 개요
Node.js는 서버사이드 자바스크립트이며 Google의 자바스크립트 엔진인 V8이 빌트인되어 있습니다. Event 기반이며 non-blocking I/O를 지원합니다. 자바스크립트의 표준라이브러리 프로젝트인 CommonJS의모듈시스템을 지원합니다.
- Event loop 방식
- 동작 요청시 동작이 완료될 경우에 실행될 Call Back을 지정하는 방식
Node.js 설치
CentOS에서 설치
yum install nodejs npm
Windows에서 설치
다운로드 사이트에서 node-v0.12.0-x64.msi 파일을 다운로드 하여 설치 합니다.
Console
node 명령을 사용하여 node Console을 실행할 수 있습니다.
종료시에는 process.exit(0); 또는 Ctrl_C + Ctrl_C를 눌러 줍니다.
Package 관리
- npm init : 패키지 관리 설정 파일인 package.json 파일을 생성 한다.
- npm install [모듈명] --save : 모듈을 설치하고 package.json 파일에 반영 한다.
mkdir -p /work/appl/modbus cd /work/appl/modbus npm init #--- scada_modbus, 0.0.1, Modbus for SCADA, scada.js, 엔터, 엔터, 엔터, OBCon, 엔터, yes This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help json` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg> --save` afterwards to install a package and save it as a dependency in the package.json file. Press ^C at any time to quit. name: (modbus) scada_modbus version: (1.0.0) 0.0.1 description: Modbus for SCADA entry point: (index.js) scada.js test command: git repository: keywords: author: OBCon license: (ISC) About to write to /work/appl/modbus/package.json: { "name": "scada_modbus", "version": "0.0.1", "description": "Modbus for SCADA", "main": "scada.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "OBCon", "license": "ISC" } Is this ok? (yes) yes # npm install [모듈명] --save #--- 모듈 설치후 package.json 파일에 추가 npm install jsmodbus --save #--- 3.1.0 npm install mocha --save #--- 5.2.0 npm install sinon --save #--- 6.3.3
Test Framework
테스트 방식
- TDD (Test-Driven Development) : 테스트 자체에 집중
- BDD (Behaviour-Driven Development) : 비즈니스 요구 사항에 집중
Karma 모듈을 설치 합니다.
- 설정 파일 : karma.conf.js, test-main.js
- 테스트 모듈 실행 : karma start karma-conf.js
npm install karma-cli -g
npm install karma -g --save-dev
npm install karma-coverage --save-dev
npm install karma-jasmine --save-dev
# npm install karma-chrome-launcher --save-dev
karma --version
karma init karma.conf.js
# Which testing framework do you want to use ? jasmine
# Do you want to use Require.js ? yes
# Do you want to capture any browsers automatically ? Chrome
# What is the location of your source and test files ?
# Should any of the files included by the previous patterns be excluded ?
# Do you wanna generate a bootstrap file for RequireJS? yes
# Do you want Karma to watch all the files and run the tests on change ? yes
환경 변수 설정 : CHROME_BIN = chrome.exe
Jasmine 모듈을 설치 합니다.
- 설정 파일 : spec/support/jasmine.json
- 테스트 모듈 실행
- js/sample.js, test/sampleSpec.js
- 모든 Test 프로그램은 ~Spec.js 형태로 작성하여야 합니다.
- jasmine-node --test-dir test --color --verbose
- jasmine-node --test-dir test --autotest --watch test --color
npm install jasmine -g
jasmine init
npm install jasmine-node -g
jasmine-node --version
참고 문헌
- Karma
- Mocha
- Supertest
- http://blog.outsider.ne.kr/1078
- http://required.cafe24.com/blog/2014/05/hello-karmajs/