1
+ require ( '../../mocks/mockAll' ) ;
2
+
3
+ import path from 'path' ;
1
4
import { scriptTask } from '../../../tasks/scriptTask' ;
2
5
import { ScriptTaskType } from '../../../types/mod.types' ;
3
6
import { taskManager } from '../../../utils/taskManager' ;
4
7
import { variables } from '../../../variables' ;
8
+ import { mockFs } from '../../mocks/mockFs' ;
5
9
6
10
describe ( 'scriptTask' , ( ) => {
7
11
it ( 'should work' , async ( ) => {
@@ -27,6 +31,10 @@ describe('scriptTask', () => {
27
31
expect ( variables . get ( 'script' ) ) . toEqual ( 'working' ) ;
28
32
} ) ;
29
33
it ( 'should require plugin' , async ( ) => {
34
+ mockFs . writeFileSync (
35
+ path . join ( __dirname , '../../mocks/mockTestPlugin.js' ) ,
36
+ 'dummy'
37
+ ) ;
30
38
const task : ScriptTaskType = {
31
39
task : 'script' ,
32
40
actions : [
@@ -43,6 +51,35 @@ describe('scriptTask', () => {
43
51
taskManager,
44
52
} ) ;
45
53
54
+ expect ( variables . get ( 'script' ) ) . toEqual ( 'working' ) ;
55
+ } ) ;
56
+ it ( 'should download non existing plugin' , async ( ) => {
57
+ mockFs . writeFileSync (
58
+ path . join ( __dirname , '../../mocks/mockTestPlugin.js' ) ,
59
+ 'dummy'
60
+ ) ;
61
+ const task : ScriptTaskType = {
62
+ task : 'script' ,
63
+ actions : [
64
+ {
65
+ module : '../../src/__tests__/mocks/mockTestPlugin.js' ,
66
+ } ,
67
+ ] ,
68
+ } ;
69
+
70
+ mockFs . existsSync . mockImplementationOnce ( ( ) => false ) ;
71
+
72
+ await scriptTask ( {
73
+ configPath : 'path/to/config' ,
74
+ task : task ,
75
+ packageName : 'test-package' ,
76
+ taskManager,
77
+ } ) ;
78
+
79
+ expect ( fetch as jest . Mock ) . toHaveBeenCalledWith (
80
+ expect . stringContaining ( 'mockTestPlugin.js' )
81
+ ) ;
82
+
46
83
expect ( variables . get ( 'script' ) ) . toEqual ( 'working' ) ;
47
84
} ) ;
48
85
} ) ;
0 commit comments