@@ -3,13 +3,24 @@ import path from 'path';
33import pify from 'pify' ;
44import test from 'ava' ;
55import tempfile from 'tempfile' ;
6+ import rimraf from 'rimraf' ;
67import Timecard from '../dist/' ;
78
89const fixtures = path . resolve ( 'test/fixtures' ) ;
910
10- test ( 'clockout' , async t => {
11- const timecard = new Timecard ( ) ;
11+ const tempfiles = [ ] ;
12+
13+ test . beforeEach ( 'cleanup tempfile' , async t => {
14+ // Create a blank timecard on the disk so that the operations
15+ // that require a timecard file can find one.
16+ const temppath = tempfile ( '.json' ) ;
17+ tempfiles . push ( temppath ) ;
18+ t . context . timecard = new Timecard ( { prompt : false , filepath : temppath } ) ;
19+ await t . context . timecard . create ( ) ;
20+ } ) ;
1221
22+ test ( 'clockout' , async t => {
23+ const timecard = t . context . timecard ;
1324 const fixture = path . join ( fixtures , 'pendingClockout.json' ) ;
1425 const data = await pify ( fs . readFile ) ( fixture , 'utf8' ) ;
1526 await timecard . load ( data ) ;
@@ -19,7 +30,7 @@ test('clockout', async t => {
1930} ) ;
2031
2132test ( 'clockout with message' , async t => {
22- const timecard = new Timecard ( ) ;
33+ const timecard = t . context . timecard ;
2334 await timecard . clockin ( 'foo' ) ;
2435 await timecard . clockout ( 'bar' ) ;
2536
@@ -28,8 +39,7 @@ test('clockout with message', async t => {
2839} ) ;
2940
3041test ( 'prevent clockout before clockin' , async t => {
31- const timecard = new Timecard ( ) ;
32-
42+ const timecard = t . context . timecard ;
3343 const fixture = path . join ( fixtures , 'blank.json' ) ;
3444 const data = await pify ( fs . readFile ) ( fixture , 'utf8' ) ;
3545 await timecard . load ( data ) ;
@@ -48,8 +58,7 @@ test('report error if attempt to clockout with no timecard', t => {
4858} ) ;
4959
5060test ( 'prevent clockout if clockin pending' , async t => {
51- const timecard = new Timecard ( ) ;
52-
61+ const timecard = t . context . timecard ;
5362 const fixture = path . join ( fixtures , 'blank.json' ) ;
5463 const data = await pify ( fs . readFile ) ( fixture , 'utf8' ) ;
5564 await timecard . load ( data ) ;
@@ -67,3 +76,10 @@ test('cant run clockout operations on illegal locations', async t => {
6776 t . true ( err . search ( 'You must create a timecard before clocking out' ) > - 1 ) ;
6877 } ) ;
6978} ) ;
79+
80+ test . after . always ( 'cleanup tempfiles' , ( ) => {
81+ tempfiles . forEach ( path => {
82+ console . log ( 'deleting temppath:' , path ) ;
83+ rimraf . sync ( path ) ;
84+ } ) ;
85+ } ) ;
0 commit comments