11import * as sinon from 'sinon'
22import * as fs from 'fs'
3+ import * as path from 'path'
34import { expect } from '@oclif/test'
45import rewriteJsAndCss from './rewriteJsAndCss'
56
@@ -17,27 +18,29 @@ describe('rewriteJsAndCss', () => {
1718 } )
1819
1920 expect ( writeFileSyncStub . callCount ) . to . equal ( 2 )
20- expect ( writeFileSyncStub . firstCall . args [ 0 ] ) . to . equal ( 'theme/path/ style.css' )
21+ expect ( writeFileSyncStub . firstCall . args [ 0 ] ) . to . equal ( path . join ( 'theme/path' , ' style.css') )
2122 expect ( writeFileSyncStub . firstCall . args [ 1 ] ) . to . equal ( 'body { color: red; }' )
22- expect ( writeFileSyncStub . secondCall . args [ 0 ] ) . to . equal ( 'theme/path/ script.js' )
23+ expect ( writeFileSyncStub . secondCall . args [ 0 ] ) . to . equal ( path . join ( 'theme/path' , ' script.js') )
2324 expect ( writeFileSyncStub . secondCall . args [ 1 ] ) . to . equal ( 'console.log("hi")' )
2425 } )
2526
2627 it ( 'throws if style.css cannot be written' , ( ) => {
28+ const cssPath = path . join ( 'theme/path' , 'style.css' )
2729 const writeFileSyncStub = sinon . stub ( fs , 'writeFileSync' )
28- writeFileSyncStub . withArgs ( 'theme/path/style.css' ) . throws ( new Error ( 'Permission denied' ) )
30+ writeFileSyncStub . withArgs ( cssPath ) . throws ( new Error ( 'Permission denied' ) )
2931
3032 expect ( ( ) => {
3133 rewriteJsAndCss ( 'theme/path' , { css : 'a' , js : 'b' } )
32- } ) . to . throw ( ' Failed to write file: theme/path/style.css' )
34+ } ) . to . throw ( ` Failed to write file: ${ cssPath } ` )
3335 } )
3436
3537 it ( 'throws if script.js cannot be written' , ( ) => {
38+ const jsPath = path . join ( 'theme/path' , 'script.js' )
3639 const writeFileSyncStub = sinon . stub ( fs , 'writeFileSync' )
37- writeFileSyncStub . withArgs ( 'theme/path/script.js' ) . throws ( new Error ( 'Permission denied' ) )
40+ writeFileSyncStub . withArgs ( jsPath ) . throws ( new Error ( 'Permission denied' ) )
3841
3942 expect ( ( ) => {
4043 rewriteJsAndCss ( 'theme/path' , { css : 'a' , js : 'b' } )
41- } ) . to . throw ( ' Failed to write file: theme/path/script.js' )
44+ } ) . to . throw ( ` Failed to write file: ${ jsPath } ` )
4245 } )
4346} )
0 commit comments