@@ -35,7 +35,7 @@ const createMocksFiles = (path: string, appName: string) => {
35
35
36
36
const createTestsFiles = ( path : string , appName : string ) => {
37
37
const filePath :string = `${ path } /${ appName } /__mocks__/gatspy.js` ;
38
- let data : `
38
+ let data = `
39
39
const React = require("react")
40
40
const gatsby = jest.requireActual("gatsby")
41
41
@@ -71,6 +71,67 @@ const createTestsFiles = (path: string, appName: string) => {
71
71
} ) ;
72
72
}
73
73
74
+ async function createJestConfigFile ( path : String , appName : String ) {
75
+ const filePath :string = `${ path } /${ appName } /jest.config.js` ;
76
+ const data :string = `
77
+ module.exports = {
78
+ transform: {
79
+ "^.+\\.tsx?$": "ts-jest",
80
+ "^.+\\.jsx?$": "<rootDir>/jest-preprocess.js",
81
+ },
82
+ testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.([tj]sx?)$",
83
+ moduleNameMapper: {
84
+ ".+\\.(css|styl|less|sass|scss)$": "identity-obj-proxy",
85
+ ".+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/file-mock.js",
86
+ },
87
+ moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
88
+ testPathIgnorePatterns: ["node_modules", ".cache"],
89
+ transformIgnorePatterns: ["node_modules/(?!(gatsby)/)"],
90
+ globals: {
91
+ __PATH_PREFIX__: '',
92
+ }
93
+ }
94
+ `
95
+ window . api . writeFile ( filePath , data , err => {
96
+ if ( err ) {
97
+ console . log ( 'createTestSuite.util createJestConfigFile error:' , err . message ) ;
98
+ } else {
99
+ console . log ( 'createTestSuit.util createJestConfigFile written successfully' ) ;
100
+ }
101
+ } ) ;
102
+ } ;
103
+
104
+ async function createJestPreprocessFile ( path : string , appName : string ) {
105
+ const filePath : string = `${ path } /${ appName } /jest-preprocess.js` ;
106
+ const data :string = `
107
+ const babelOptions = {
108
+ presets: ["babel-preset-gatsby"],
109
+ }
110
+
111
+ module.exports = require("babel-jest").default.createTransformer(babelOptions)` ;
112
+
113
+ window . api . writeFile ( filePath , data , err => {
114
+ if ( err ) {
115
+ console . log ( 'createTestSuite.util createJestPreprocessFile error:' , err . message ) ;
116
+ } else {
117
+ console . log ( 'createTestSuit.util createJestPreprocessFile written successfully' ) ;
118
+ }
119
+ } ) ;
120
+ }
121
+
122
+ async function createComponentTests ( path : string , appName : string , components : Component [ ] ) {
123
+ const filePath : string = `${ path } /${ appName } /__tests__/test.tsx` ;
124
+ const data :string = '' ;
125
+
126
+ window . api . writeFile ( filePath , data , err => {
127
+ if ( err ) {
128
+ console . log ( 'createTestSuite.util createComponentTests error:' , err . message ) ;
129
+ } else {
130
+ console . log ( 'createTestSuit.util createComponentTests written successfully' ) ;
131
+ }
132
+ } ) ;
133
+ }
134
+
74
135
async function createTestSuite ( {
75
136
path,
76
137
appName,
@@ -90,6 +151,9 @@ async function createTestSuite({
90
151
await initFolders ( path , appName ) ;
91
152
await createMocksFiles ( path , appName ) ;
92
153
await createTestsFiles ( path , appName ) ;
154
+ await createJestConfigFile ( path , appName ) ;
155
+ await createJestPreprocessFile ( path , appName ) ;
156
+ await createComponentTests ( path , appName , components ) ;
93
157
}
94
158
95
159
export default createTestSuite ;
0 commit comments