Skip to content

Commit

Permalink
Merge pull request #17 from ademuk/test-names
Browse files Browse the repository at this point in the history
Name tests
  • Loading branch information
ademuk committed Dec 16, 2020
2 parents 148ed82 + b063e43 commit 384f0b5
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 267 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-json-editor-ajrm": "^2.5.13",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.4.3",
"tailwindcss": "^1.4.6",
"tailwindcss": "1.9.0",
"ts-loader": "^8.0.7",
"ts-morph": "^8.1.2",
"typescript": "^4.0.3",
Expand Down
49 changes: 30 additions & 19 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const writeFile = (file, payload) =>
`${file}.tests.json`,
JSON.stringify(payload, null, 2),
err => {
err ? reject() : resolve();
err ? reject() : resolve(payload);
}
)
);
Expand Down Expand Up @@ -416,9 +416,9 @@ const createTest = (file, exportName) => {
.then(() => test)
};

const testWithUpdatedSteps = (test, steps) => ({
const updatedTest = (test, updates) => ({
...test,
steps
...updates
});

const componentWithAddedTest = (component, test) => ({
Expand All @@ -433,32 +433,33 @@ const fileJsonWithAddedTest = (fileJson, exportName, test) => ({
)
});

const componentWithUpdatedTest = (component, testId, steps) => ({
const componentWithUpdatedTest = (component, testId, testUpdates) => ({
...component,
tests: component.tests.map(t => t.id === testId ? testWithUpdatedSteps(t, steps) : t)
tests: component.tests.map(t => t.id === testId ? updatedTest(t, testUpdates) : t)
});

const fileJsonWithUpdatedComponent = (fileJson, exportName, testId, steps) => ({
const fileJsonWithUpdatedTest = (fileJson, exportName, testId, testUpdates) => ({
...fileJson,
components: fileJson.components.map(c =>
c.name === exportName ? componentWithUpdatedTest(c, testId, steps) : c
c.name === exportName ? componentWithUpdatedTest(c, testId, testUpdates) : c
)
});


const updateTestName = (file, exportName, testId, name) =>
getTestFile(file)
.then(fileJson =>
writeFile(file, fileJsonWithUpdatedTest(fileJson, exportName, testId, {name}))
);

const updateTestSteps = (file, exportName, testId, steps) =>
getTestFile(file)
.then(fileJson => {
const payload = fileJsonWithUpdatedComponent(fileJson, exportName, testId, steps);
return new Promise((resolve, reject) => {
fs.writeFile(
`${file}.tests.json`,
JSON.stringify(payload, null, 2),
(err) => {
err ? reject() : resolve(payload);
}
);
})
});
.then(fileJson =>
writeFile(
file,
fileJsonWithUpdatedTest(fileJson, exportName, testId, {steps})
)
);

class RenderError extends Error {
public componentStack?: string;
Expand Down Expand Up @@ -776,6 +777,16 @@ app.put(
.catch(next)
);

app.put(
'/test/:testId/name',
(req, res, next) =>
updateTestName(path.join(SEARCH_PATH, (req.query.file as string)), req.query.exportName, req.params.testId, req.body.name)
.then(
test => res.send(test)
)
.catch(next)
);

app.get(
'/test/:testId/render/side-effects',
(req, res, next) =>
Expand Down
Loading

0 comments on commit 384f0b5

Please sign in to comment.