File tree 5 files changed +43
-4
lines changed
5 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ node_modules/
2
2
bin /
3
3
src /** /* .js
4
4
src /** /* .d.ts
5
+ __tests__ /auth.json
Original file line number Diff line number Diff line change
1
+ {
2
+ "username" : " UserName" ,
3
+ "password" : " YourPassword(keep gitignored!)"
4
+ }
Original file line number Diff line number Diff line change
1
+ import { username , password } from "./auth.json" ;
2
+ import inquirer from "inquirer" ;
3
+ import { AtCoder } from "../src/atcoder" ;
4
+ import { Cookie } from "../src/cookie" ;
5
+
6
+ jest . mock ( "inquirer" ) ;
7
+
8
+ /*
9
+ * Cookieファイルの実装を差し替えておく
10
+ * コンフィグファイルとの読み書きを行わず、必ず空のセッションが返るようにする
11
+ */
12
+ Cookie . prototype . loadConfigFile = jest . fn ( async function ( ) {
13
+ // @ts -ignore
14
+ this . cookies = [ ]
15
+ } ) ;
16
+ Cookie . prototype . saveConfigFile = jest . fn ( async function ( ) {
17
+ } ) ;
18
+
19
+ /*
20
+ このテストが失敗する場合、まず以下の点を確認してください
21
+ - __tests__/auth.json が存在し、正しいユーザー名とパスワードが記述されていること
22
+ すべてのテストを開始する前に、__tests__/auth.example.jsonをコピーして__tests__/auth.json を作成し、
23
+ 有効なAtCoderアカウントのユーザー名とパスワードを記述してください
24
+ __tests__/auth.jsonはgit管理に含めないように注意してください
25
+ */
26
+ test ( "AtCoder Login" , async ( ) => {
27
+ const atcoder = new AtCoder ( ) ;
28
+ expect ( await atcoder . checkSession ( ) ) . toBe ( false ) ;
29
+
30
+ // ユーザー名とパスワードを標準入力で受け付けるかわりにファイルから流し込むようモックする
31
+ // @ts -ignore
32
+ inquirer . prompt . mockResolvedValueOnce ( { username, password} ) ;
33
+
34
+ expect ( await atcoder . login ( ) ) . toBe ( true ) ;
35
+ expect ( await atcoder . checkSession ( true ) ) . toBe ( true ) ;
36
+ } ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 12
12
"resolveJsonModule" : true
13
13
},
14
14
"exclude" : [
15
- " node_modules"
15
+ " node_modules" ,
16
+ " __tests__"
16
17
]
17
18
}
You can’t perform that action at this time.
0 commit comments