Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit54d46e5

Browse files
committed
setup first test with atom mocks
1 parentb12f581 commit54d46e5

File tree

7 files changed

+85
-14
lines changed

7 files changed

+85
-14
lines changed

‎.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
node_modules
33
npm-debug.log
44
test
5+
.vscode
6+
src/coverage
7+
src/__tests__/__cache__
8+
src/__tests__/__snapshots__

‎.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ tsconfig.json
77
tsd.json
88
tslint.json
99
.gitattributes
10+
.vscode
11+
src/coverage
12+
src/__tests__/__cache__
13+
src/__tests__/__snapshots__

‎package.json

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"repository":"https://github.com/coderoad/atom-coderoad",
2727
"scripts": {
2828
"compile":"tsc",
29-
"test":"tsc test/*.ts src/typings.d.ts && ava"
29+
"test":"jest"
3030
},
3131
"dependencies": {
3232
"atom-plugin-command-line":"1.0.2",
@@ -44,6 +44,13 @@
4444
"redux-thunk":"2.1.0",
4545
"reselect":"2.5.3"
4646
},
47+
"devDependencies": {
48+
"enzyme":"^2.4.1",
49+
"jest":"^15.1.1",
50+
"react-addons-test-utils":"^15.3.1",
51+
"react-test-renderer":"^15.3.1",
52+
"tslint":"^3.15.1"
53+
},
4754
"engines": {
4855
"atom":">=1.0.0 <2.0.0"
4956
},
@@ -57,16 +64,30 @@
5764
}
5865
}
5966
},
60-
"devDependencies": {
61-
"enzyme":"^2.4.1",
62-
"jest":"^15.1.1",
63-
"react-addons-test-utils":"^15.3.1",
64-
"react-test-renderer":"^15.3.1",
65-
"tslint":"^3.15.1"
66-
},
6767
"jest": {
68+
"verbose":true,
6869
"scriptPreprocessor":"<rootDir>/src/__tests__/preprocessor.js",
69-
"moduleFileExtensions": ["ts","tsx","js"],
70-
"testRegex":"/src/*/.*\\.test\\.(ts|tsx|js)$"
70+
"moduleFileExtensions": [
71+
"ts",
72+
"tsx",
73+
"js"
74+
],
75+
"testRegex":"/src/*/.*\\.test\\.(ts|tsx|js)$",
76+
"coverageDirectory":"src/coverage",
77+
"collectCoverage":true,
78+
"coveragePathIgnorePatterns": [
79+
"/node_modules/",
80+
"/typings/",
81+
"__tests__"
82+
],
83+
"coverageThreshold": {
84+
"global": {
85+
"branches":50,
86+
"functions":50,
87+
"lines":50,
88+
"statements":50
89+
}
90+
},
91+
"cacheDirectory":"src/__tests__/__cache__"
7192
}
7293
}

‎src/__tests__/mocks/atom.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Mock atom file path
3+
*@param {string} path file path
4+
*/
5+
exportconstatomPath=(path:string)=>({
6+
project:{
7+
rootDirectories:[{
8+
path
9+
}]
10+
}
11+
});

‎src/modules/dir/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
/**
2+
* User directory path Redux reducer
3+
*@param {string} dir default user directory path
4+
*@returns string user directory path
5+
*/
16
exportdefaultfunctiondirReducer(
27
dir:string
38
):string{
4-
if(atom.project.rootDirectories.length>0){
9+
if(!atom){
10+
thrownewError('No project directory found. Atom may not be initialized.');
11+
}
12+
if(atom&&atom.project.rootDirectories.length>0){
513
returnatom.project.rootDirectories[0].path;
6-
}else{
7-
return'';
814
}
15+
returndir;
916
}

‎src/modules/dir/reducer.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
importdirfrom'./index';
2+
import{atomPath}from'../../__tests__/mocks/atom';
3+
4+
describe('dir reducer',()=>{
5+
6+
afterEach(()=>{
7+
global.atom=null;
8+
});
9+
10+
it('should return the project directory in Atom',()=>{
11+
constpathToDir='./path/to/dir';
12+
global.atom=atomPath(pathToDir);
13+
expect(dir()).toBe(pathToDir);
14+
});
15+
16+
it('should throw an error if no project directory is found',()=>{
17+
expect(()=>dir()).toThrowError(/Noprojectdirectory/);
18+
});
19+
20+
});

‎tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
"*.ts",
2121
"**/*.ts",
2222
"**/*.tsx",
23+
"!coverage",
24+
"!__tests__",
2325
"!**/*.spec.ts",
24-
"!**/*.spec.tsx"
26+
"!**/*.spec.tsx",
27+
"!**/*.test.ts",
28+
"!**/*.test.tsx"
2529
],
2630
"exclude": [
2731
"node_modules"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp