-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from tddbc/skelton
add skelton of jest
- Loading branch information
Showing
15 changed files
with
6,440 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"extends": "standard", | ||
"globals": { | ||
"test": true, | ||
"expect": true | ||
}, | ||
"rules": { | ||
"indent": "off", | ||
"quotes": "off", | ||
"semi": "off", | ||
"space-before-function-paren": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- 11 | ||
- 10 | ||
- 9 | ||
|
||
cache: npm | ||
script: | ||
- npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,75 @@ | ||
# javascript-jest | ||
skelton for Node.js + Jest | ||
# TDDBC for JavaScript + Jest with Node.js | ||
|
||
これは、TDDBCのNode.js + Jest 向けプロジェクトです。 | ||
|
||
## Documentation | ||
|
||
### セットアップ&テスト | ||
|
||
|
||
```sh | ||
$ git clone https://github.com/tddbc/javascript-jest.git | ||
$ cd javascript-jest | ||
$ npm install | ||
$ npm run test:test | ||
|
||
> [email protected] pretest /Users/dictav/golang/src/github.com/dictav/javascript-jest | ||
> npm run fmt && npm run lint | ||
|
||
> [email protected] fmt /Users/dictav/golang/src/github.com/dictav/javascript-jest | ||
> prettier --write *js *.json lib/*js | ||
|
||
jest_js.config.js 53ms | ||
jest_mjs.config.js 7ms | ||
main.js 8ms | ||
main.mjs 7ms | ||
prettier.config.js 4ms | ||
package-lock.json 355ms | ||
package.json 30ms | ||
lib/sample.js 11ms | ||
lib/sample.mjs 7ms | ||
lib/sample_test.js 11ms | ||
lib/sample_test.mjs 7ms | ||
|
||
> [email protected] lint /Users/dictav/golang/src/github.com/dictav/javascript-jest | ||
> eslint main.js main.mjs lib/*js | ||
|
||
> [email protected] test /Users/dictav/golang/src/github.com/dictav/javascript-jest | ||
> npm run test:js && npm run test:mjs | ||
|
||
> [email protected] test:js /Users/dictav/golang/src/github.com/dictav/javascript-jest | ||
> jest --config jest_js.config.js | ||
|
||
PASS lib/sample_test.js | ||
✓ exported class (2ms) | ||
✓ private function (2ms) | ||
|
||
Test Suites: 1 passed, 1 total | ||
Tests: 2 passed, 2 total | ||
Snapshots: 0 total | ||
Time: 1.154s, estimated 2s | ||
Ran all test suites. | ||
``` | ||
|
||
### コマンド | ||
|
||
| コマンド | 内容 | | ||
|:--------------------|:-----------------------------------------------------------| | ||
| `npm test` | lint とテストをまとめて行います | | ||
| `npm test:js` | CommonJS の実装のテストを行います | | ||
| `npm test:mjs` | ES Module の実装のテストを行います | | ||
| `npm run fmt` | コードの整形を行います | | ||
| `npm run lint` | コードの静的検証を行います | | ||
| `npm run watch:js` | ファイル変更を監視し、変更があったらテストを自動で行います | | ||
| `npm run watch:mjs` | ファイル変更を監視し、変更があったらテストを自動で行います | | ||
|
||
|
||
## License | ||
|
||
Copyright (c) 2019 TDD BaseCamp and other contributors | ||
|
||
http://devtesting.jp/tddbc/ | ||
|
||
https://github.com/tddbc | ||
|
||
Licensed under the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
testEnvironment: "node", | ||
testRegex: ".*_test\\.js$", | ||
moduleFileExtensions: ["js", "json", "jsx", "node", "mjs"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
module.exports = { | ||
testEnvironment: "node", | ||
testRegex: ".*_test\\.mjs$", | ||
transform: { | ||
".*\\.mjs$": "esm" | ||
}, | ||
transformIgnorePatterns: ["/node_modules/"], | ||
moduleFileExtensions: ["js", "json", "jsx", "node", "mjs"] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Sample { | ||
constructor(printFunc) { | ||
this.print = printFunc || console.log; | ||
} | ||
|
||
say() { | ||
this.print(hello()); | ||
} | ||
} | ||
|
||
function hello() { | ||
return "Hello TDDBC!"; | ||
} | ||
|
||
module.exports = Sample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default class Sample { | ||
constructor(printFunc) { | ||
this.print = printFunc || console.log; | ||
} | ||
|
||
say() { | ||
this.print(hello()); | ||
} | ||
} | ||
|
||
function hello() { | ||
return "Hello TDDBC!"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const assert = require("assert").strict; | ||
const Sample = require("./sample"); | ||
const rewire = require("rewire"); | ||
|
||
test("exported class", () => { | ||
let ret = ""; | ||
const print = str => (ret = str); | ||
const sample = new Sample(print); | ||
sample.say(); | ||
assert.equal(ret, "Hello TDDBC!"); | ||
}); | ||
|
||
const SampleImpl = rewire("./sample"); | ||
test("private function", () => { | ||
const hello = SampleImpl.__get__("hello"); | ||
expect(hello()).toBe("Hello TDDBC!"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { strict as assert } from "assert"; | ||
import Sample from "./sample"; | ||
import rewire from "rewire"; | ||
|
||
test("exported class", () => { | ||
let ret = ""; | ||
const print = str => (ret = str); | ||
const sample = new Sample(print); | ||
sample.say(); | ||
assert.equal(ret, "Hello TDDBC!"); | ||
}); | ||
|
||
const SampleImpl = rewire("./sample"); | ||
test("private function", () => { | ||
const hello = SampleImpl.__get__("hello"); | ||
expect(hello()).toBe("Hello TDDBC!"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const Sample = require("./js/sample"); | ||
const sample = new Sample(); | ||
sample.say(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Sample from "./lib/sample"; | ||
|
||
let sample = new Sample(console.log); | ||
sample.say(); |
Oops, something went wrong.