Skip to content

Introduce Typescript for only Tests #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- run:
name: Run Test
command: yarn test
command: yarn test:coverage

- run:
name: Report Coverage
Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"editor.insertSpaces": true,
"files.trimTrailingWhitespace": true,
"files.autoSave": "onFocusChange",
"files.exclude": {
"**/build/": true,
"lib": true
},
"search.exclude": {
"coverage": true,
".nyc_output": true
},
"eslint.autoFixOnSave": true
}
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "react-simple-image",
"version": "0.1.3",
"description": "responsive <img> tag with cleaner srcset/sizes interface.",
"main": "lib/image.js",
"main": "lib/Image.js",
"scripts": {
"lint": "eslint src/**/*.{js,jsx} spec/**/*.{js,jsx}",
"build": "babel src --out-dir lib --source-maps",
"pretest": "yarn build",
"test": "NODE_ENV=test nyc mocha --opts spec/mocha.opts spec/**/*.spec.jsx",
"lint": "eslint src/**/*.{js,jsx} test/**/*.{js,jsx}",
"test": "NODE_PATH=. NODE_ENV=test TS_NODE_PROJECT=test/tsconfig.json mocha",
"test:coverage": "NODE_PATH=. NODE_ENV=test TS_NODE_PROJECT=test/tsconfig.json nyc mocha",
"coveralls": "NODE_ENV=test nyc report --reporter=text-lcov | $(npm bin)/coveralls",
"story:start": "start-storybook -p 9001 -c .storybook",
"story:build": "build-storybook -c .storybook -o build",
Expand Down Expand Up @@ -36,6 +36,9 @@
"homepage": "https://github.com/bitjourney/react-simple-image#readme",
"devDependencies": {
"@kadira/storybook": "^2.35.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.18",
"@types/power-assert": "^1.4.29",
"babel-cli": "^6.14.0",
"babel-plugin-istanbul": "^3.0.0",
"babel-preset-es2015": "^6.18.0",
Expand All @@ -52,7 +55,10 @@
"nyc": "^10.0.0",
"power-assert": "^1.4.2",
"react": "^15.4.1",
"react-dom": "^15.4.1"
"react-dom": "^15.4.1",
"source-map-support": "^0.4.15",
"ts-node": "^3.0.4",
"typescript": "^2.3.2"
},
"peerDependencies": {
"react": "^15.4.1"
Expand All @@ -73,7 +79,9 @@
"babel-register"
],
"extension": [
".jsx"
".jsx",
".ts",
".tsx"
],
"reporter": [
"text"
Expand Down
2 changes: 0 additions & 2 deletions spec/mocha.opts

This file was deleted.

2 changes: 1 addition & 1 deletion src/image.jsx → src/Image.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import * as React from 'react';
import { matchDescriptor, matchWidthDescriptor, matchPixelDescriptor } from './matcher';

export default class Image extends React.Component {
Expand Down
4 changes: 2 additions & 2 deletions spec/image.spec.jsx → test/Image.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'power-assert';
import * as assert from 'power-assert';
import { renderToString } from 'react-dom/server';
import { createElement } from 'react';
import Image from '../src/image';
import Image from 'src/Image';

describe('Image', () => {
describe('with width descriptor', () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/matcher.spec.js → test/matcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'power-assert';
import { matchDescriptor, matchWidthDescriptor, matchPixelDescriptor } from '../src/matcher';
import * as assert from 'power-assert';
import { matchDescriptor, matchWidthDescriptor, matchPixelDescriptor } from 'src/matcher';

describe('Matcher', () => {
const validWidths = [
Expand Down
11 changes: 11 additions & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--compilers ts:ts-node/register,tsx:ts-node/register

--require source-map-support/register
--require test/resolver.js

--check-leaks
--full-trace
--recursive
--timeout 1000

test/**/*.spec.{ts,tsx}
13 changes: 13 additions & 0 deletions test/resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint "no-underscore-dangle": "off" */
const Module = require('module');

const originalLoader = Module._load;
const patchedLoader = (request, parent, isMain) => {
try {
return originalLoader.call(null, request, parent, isMain);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node.jsの Module.__load にパッチを当てています https://github.com/nodejs/node/blob/master/lib/module.js#L432

これが見つからなかったら .jsx 拡張子を当てて再度ロードするようにしています。本体であればいくつかのケースに備えて作る必要がありそうですが、本質的にはこのような解決策でいけそうです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最終的にすべてのファイルが TypeScript 化し、resolveする必要がなくなったらこのファイルをまるっと消せば良さそうです。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど。いずれ消す前提ならこれでいいと思います。

} catch (error) {
const newRequest = `${request}.jsx`;
return originalLoader.call(null, newRequest, parent, isMain);
}
};
Module._load = patchedLoader;
24 changes: 24 additions & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": false,
"lib": [
"es2015"
],
"module": "commonjs",
"moduleResolution": "node",
"noEmitOnError": true,
"outDir": "build/",
"baseUrl": "..",
"paths": {
"*": [
"*"
]
},
"removeComments": true,
"sourceMap": true,
"strictNullChecks": true,
"target": "es5",
"jsx": "react"
}
}
106 changes: 96 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@
webpack-dev-middleware "^1.6.0"
webpack-hot-middleware "^2.13.2"

"@types/empower@*":
version "1.2.30"
resolved "https://registry.yarnpkg.com/@types/empower/-/empower-1.2.30.tgz#c7cfc14b3a61e54c74c674c1fbc91ba2df0d1392"

"@types/mocha@^2.2.41":
version "2.2.41"
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.41.tgz#e27cf0817153eb9f2713b2d3f6c68f1e1c3ca608"

"@types/node@^7.0.18":
version "7.0.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-7.0.18.tgz#cd67f27d3dc0cfb746f0bdd5e086c4c5d55be173"

"@types/power-assert-formatter@*":
version "1.4.28"
resolved "https://registry.yarnpkg.com/@types/power-assert-formatter/-/power-assert-formatter-1.4.28.tgz#25b8fddb6322259c6b91c35338d39b0f8e524252"

"@types/power-assert@^1.4.29":
version "1.4.29"
resolved "https://registry.yarnpkg.com/@types/power-assert/-/power-assert-1.4.29.tgz#51f8366f62ad6a111f5e7fa94920c4923cffaeb6"
dependencies:
"@types/empower" "*"
"@types/power-assert-formatter" "*"

abab@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d"
Expand Down Expand Up @@ -197,6 +220,10 @@ ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"

any-promise@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f"

anymatch@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.0.tgz#a3e52fa39168c825ff57b0248126ce5a8ff95507"
Expand Down Expand Up @@ -1707,6 +1734,10 @@ diff@1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf"

diff@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/diff/-/diff-3.2.0.tgz#c9ce393a4b7cbd0b058a725c93df299027868ff9"

doctrine@1.5.0, doctrine@^1.2.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa"
Expand Down Expand Up @@ -3119,6 +3150,10 @@ macaddress@^0.2.8:
version "0.2.8"
resolved "https://registry.yarnpkg.com/macaddress/-/macaddress-0.2.8.tgz#5904dc537c39ec6dbefeae902327135fa8511f12"

make-error@^1.1.1:
version "1.2.3"
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.2.3.tgz#6c4402df732e0977ac6faf754a5074b3d2b1d19d"

mantra-core@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/mantra-core/-/mantra-core-1.7.0.tgz#a8c83e8cee83ef6a7383131519fe8031ad546386"
Expand Down Expand Up @@ -3431,6 +3466,10 @@ object-assign@^4.0.1, object-assign@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0"

object-assign@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"

object-keys@^1.0.0, object-keys@^1.0.8:
version "1.0.11"
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
Expand Down Expand Up @@ -4061,18 +4100,14 @@ q@^1.1.2:
version "1.4.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.4.1.tgz#55705bcd93c5f3673530c2c2cbc0c2b3addc286e"

qs@6.2.0:
qs@6.2.0, qs@~6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.0.tgz#3b7848c03c2dece69a9522b0fae8c4126d745f3b"

qs@^6.1.0, qs@^6.2.0, qs@~6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.3.0.tgz#f403b264f23bc01228c74131b407f18d5ea5d442"

qs@~6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/qs/-/qs-6.2.1.tgz#ce03c5ff0935bc1d9d69a9f14cbd18e568d67625"

query-string@^4.1.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.2.3.tgz#9f27273d207a25a8ee4c7b8c74dcd45d556db822"
Expand Down Expand Up @@ -4593,11 +4628,11 @@ source-list-map@^0.1.4, source-list-map@~0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-0.1.7.tgz#d4b5ce2a46535c72c7e8527c71a77d250618172e"

source-map-support@^0.4.2:
version "0.4.7"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.7.tgz#7a7988e0e66241c778c78dd179199bb6bcd35bd6"
source-map-support@^0.4.0, source-map-support@^0.4.15, source-map-support@^0.4.2:
version "0.4.15"
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.15.tgz#03202df65c06d2bd8c7ec2362a193056fef8d3b1"
dependencies:
source-map "^0.5.3"
source-map "^0.5.6"

source-map@^0.4.4, source-map@~0.4.1:
version "0.4.4"
Expand Down Expand Up @@ -4747,6 +4782,10 @@ strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"

strip-json-comments@^2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a"

strip-json-comments@~1.0.1, strip-json-comments@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91"
Expand Down Expand Up @@ -4877,6 +4916,43 @@ tryit@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/tryit/-/tryit-1.0.3.tgz#393be730a9446fd1ead6da59a014308f36c289cb"

ts-node@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-3.0.4.tgz#a1475ebf24fd4e2ee2fba8b1aa1605b977bde506"
dependencies:
arrify "^1.0.0"
chalk "^1.1.1"
diff "^3.1.0"
make-error "^1.1.1"
minimist "^1.2.0"
mkdirp "^0.5.1"
source-map-support "^0.4.0"
tsconfig "^6.0.0"
v8flags "^2.0.11"
yn "^1.2.0"

tsconfig-paths@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-2.1.2.tgz#8f08fca7c52bfa9697f931624b5612682a78c373"
dependencies:
tsconfig "^5.0.3"

tsconfig@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-5.0.3.tgz#5f4278e701800967a8fc383fd19648878f2a6e3a"
dependencies:
any-promise "^1.3.0"
parse-json "^2.2.0"
strip-bom "^2.0.0"
strip-json-comments "^2.0.0"

tsconfig@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/tsconfig/-/tsconfig-6.0.0.tgz#6b0e8376003d7af1864f8df8f89dd0059ffcd032"
dependencies:
strip-bom "^3.0.0"
strip-json-comments "^2.0.0"

tty-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
Expand Down Expand Up @@ -4910,6 +4986,10 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.3.2.tgz#f0f045e196f69a72f06b25fd3bd39d01c3ce9984"

ua-parser-js@^0.7.9:
version "0.7.12"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
Expand Down Expand Up @@ -5003,7 +5083,7 @@ uuid@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.0.1.tgz#6544bba2dfda8c1cf17e629a3a305e2bb1fee6c1"

v8flags@^2.0.10:
v8flags@^2.0.10, v8flags@^2.0.11:
version "2.0.11"
resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.0.11.tgz#bca8f30f0d6d60612cc2c00641e6962d42ae6881"
dependencies:
Expand Down Expand Up @@ -5230,3 +5310,9 @@ yargs@~3.10.0:
cliui "^2.1.0"
decamelize "^1.0.0"
window-size "0.1.0"

yn@^1.2.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/yn/-/yn-1.3.0.tgz#1b0812abb8d805d48966f8df385dc9dacc9a19d8"
dependencies:
object-assign "^4.1.1"