Skip to content

Commit f901709

Browse files
committed
finished setting up Gastby app test connect exports, ready for unit testing, Philip, https://github.com/pmhua, Daniel https://github.com/dreille, William https://github.com/wbrittwage, Miles https://github.com/Miles818
1 parent b73aaf3 commit f901709

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

app/src/helperFunctions/generateCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ const generateUnformattedCode = (
274274
${links ? `import { Link } from 'gatsby'` : ``}
275275
276276
277-
const ${currentComponent.name} = (props): JSX.Element => {
277+
const ${currentComponent.name} = (props: any): JSX.Element => {
278278
279279
const [value, setValue] = useState<any | undefined>("INITIAL VALUE");
280280

app/src/utils/createGatsbyApp.util.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,24 @@ export const createPackage = (path, appName, test) => {
7979
};
8080
//createTSConfig (empty)
8181
export const createTsConfig = (path, appName) => {
82-
const filePath = `${path}/${appName}/tsconfig.json`;
82+
const filePath:string = `${path}/${appName}/tsconfig.json`;
8383
//running 'gatsby dev' will autopopulate this with default values
84-
window.api.writeFile(filePath, '', err => {
84+
const data:string = `{
85+
"compilerOptions": {
86+
"outDir": "./dist/",
87+
"sourceMap": true,
88+
"noImplicitAny": true,
89+
"module": "commonjs",
90+
"target": "esnext",
91+
"jsx": "react",
92+
"lib": ["dom", "esnext"],
93+
"moduleResolution": "node",
94+
"esModuleInterop": true
95+
},
96+
"include": ["./src/**/*"]
97+
}
98+
`;
99+
window.api.writeFile(filePath, data, err => {
85100
if (err) {
86101
console.log('TSConfig error:', err.message);
87102
} else {

app/src/utils/createTestSuite.util.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,48 @@ async function createJestPreprocessFile(path: string, appName: string){
121121

122122
async function createComponentTests(path: string, appName: string, components: Component[]) {
123123
const filePath: string = `${path}/${appName}/__tests__/test.tsx`;
124-
const data:string = '';
124+
console.log(JSON.stringify(components))
125+
console.log(components);
125126

127+
let data:string = `
128+
import React from "react"
129+
import renderer from "react-test-renderer"
130+
import Enzyme, { shallow } from 'enzyme';
131+
132+
133+
import Adapter from 'enzyme-adapter-react-16';
134+
Enzyme.configure({ adapter: new Adapter() });
135+
`;
136+
137+
components.forEach(page => {
138+
139+
let importString = `
140+
import ${capitalize(page.name)} from "../src/pages/${page.name}";`;
141+
data = data + importString;
142+
})
143+
144+
//let describe = `describe("${page.name}", () => {`
145+
components.forEach(page => {
146+
data = data + `
147+
148+
describe("${capitalize(page.name)}", () => {`
149+
150+
151+
data = data + `
152+
it("renders correctly", () => {
153+
const tree = renderer
154+
.create(<${capitalize(page.name)} />)
155+
.toJSON()
156+
expect(tree).toMatchSnapshot()
157+
})`
158+
159+
160+
data = data + `
161+
});`
162+
})
163+
164+
165+
126166
window.api.writeFile(filePath, data, err => {
127167
if (err) {
128168
console.log('createTestSuite.util createComponentTests error:', err.message);
@@ -132,6 +172,11 @@ async function createComponentTests(path: string, appName: string, components: C
132172
});
133173
}
134174

175+
const capitalize = (string: string) => {
176+
return string.charAt(0).toUpperCase() + string.slice(1);
177+
}
178+
179+
135180
async function createTestSuite({
136181
path,
137182
appName,

0 commit comments

Comments
 (0)