Skip to content

Commit

Permalink
Merge pull request #1 from tddbc/skelton
Browse files Browse the repository at this point in the history
add skelton of jest
  • Loading branch information
dictav authored Feb 3, 2019
2 parents 446b507 + 1031e7f commit dccbff0
Show file tree
Hide file tree
Showing 15 changed files with 6,440 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .eslintrc.json
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"
}
}
9 changes: 9 additions & 0 deletions .travis.yml
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
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
MIT License

Copyright (c) 2019 TDDBC
Copyright (c) 2019 TDDBC and other contributors
http://devtesting.jp/tddbc/
https://github.com/tddbc

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
77 changes: 75 additions & 2 deletions README.md
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.
8 changes: 8 additions & 0 deletions jest_js.config.js
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"]
};
12 changes: 12 additions & 0 deletions jest_mjs.config.js
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"]
};
15 changes: 15 additions & 0 deletions lib/sample.js
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;
13 changes: 13 additions & 0 deletions lib/sample.mjs
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!";
}
17 changes: 17 additions & 0 deletions lib/sample_test.js
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!");
});
17 changes: 17 additions & 0 deletions lib/sample_test.mjs
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!");
});
3 changes: 3 additions & 0 deletions main.js
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();
4 changes: 4 additions & 0 deletions main.mjs
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();
Loading

0 comments on commit dccbff0

Please sign in to comment.