Skip to content

Commit b73aaf3

Browse files
committed
finsihed setting up gatsby app connection files for export, Philip, https://github.com/pmhua, Daniel https://github.com/dreille, William https://github.com/wbrittwage, Miles https://github.com/Miles818
1 parent 065ad03 commit b73aaf3

File tree

1 file changed

+65
-1
lines changed

1 file changed

+65
-1
lines changed

app/src/utils/createTestSuite.util.ts

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const createMocksFiles = (path: string, appName: string) => {
3535

3636
const createTestsFiles = (path: string, appName: string) => {
3737
const filePath:string = `${path}/${appName}/__mocks__/gatspy.js`;
38-
let data: `
38+
let data = `
3939
const React = require("react")
4040
const gatsby = jest.requireActual("gatsby")
4141
@@ -71,6 +71,67 @@ const createTestsFiles = (path: string, appName: string) => {
7171
});
7272
}
7373

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+
74135
async function createTestSuite({
75136
path,
76137
appName,
@@ -90,6 +151,9 @@ async function createTestSuite({
90151
await initFolders(path, appName);
91152
await createMocksFiles(path, appName);
92153
await createTestsFiles(path, appName);
154+
await createJestConfigFile(path, appName);
155+
await createJestPreprocessFile(path, appName);
156+
await createComponentTests(path, appName, components);
93157
}
94158

95159
export default createTestSuite;

0 commit comments

Comments
 (0)