-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: add smoke test for generator-options command - stdout echoed (#163) * chore: generator-options smoke test added (#163) * chore: wip smoke test-generators (#163) * chore: write smoke test in JS, all three commands pass * chore: pass smoke test work to JS instead of Github Actions * chore: move noisy logs to log file * chore: log available on step failure, clean up comments * chore: revert delete of workflow files * fix: incorrectly removed line * chore: print installed JS and TS generator versions in smoke test * chore: pass test-generators if it has >= passes cpw master
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Smoke Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- "**" | ||
pull_request: | ||
branches: | ||
- "**" | ||
|
||
jobs: | ||
smoke-tests: | ||
name: Smoke Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out Git repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: 'npm' | ||
|
||
- name: Install Node.js dependencies | ||
run: | | ||
npm install | ||
- id: smoke_test | ||
name: Smoke Test generator-options, test-generators and forge commands | ||
run: | | ||
npm run test:smoke | ||
- id: show_full_log | ||
name: Show Full Log | ||
if: success() || failure() | ||
run: | | ||
cat log.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
const shell = require("shelljs"); | ||
const fs = require("fs"); | ||
|
||
const jsGeneratorLocation = "smoke-js"; | ||
const tsGeneratorLocation = "smoke-ts"; | ||
|
||
const cloneRepoToPath = (repoPath, destPath, returnPath) => { | ||
const cloneStdout = shell.exec(`git clone ${repoPath} ${destPath}`, { | ||
silent: true, | ||
}).stdout; | ||
shell.cd(destPath); | ||
const installStdout = shell.exec("npm install", { silent: true }).stdout; | ||
const latestVersion = getLatestGitVersionTag(repoPath); | ||
shell.cd(returnPath); | ||
return cloneStdout + "\r\n" + latestVersion + "\r\n" + installStdout; | ||
}; | ||
|
||
const getLatestGitVersionTag = (repoPath) => | ||
"Version of " + | ||
repoPath + | ||
" installed: " + | ||
shell.exec(`git tag --sort=committerdate | tail -1`, { | ||
silent: true, | ||
}).stdout; | ||
|
||
const gitCheckout = (branch) => | ||
shell.exec(`git fetch && git checkout ${branch}`, { silent: true }).stdout; | ||
|
||
const runTestGenerators = () => | ||
JSON.parse( | ||
shell.exec( | ||
`node ./src/index.js test-generators --generators ${tsGeneratorLocation} --format json --logLevel quiet`, | ||
{ silent: true } | ||
).stdout | ||
); | ||
|
||
// NOTE: The JS and TS generators are installed in different relative paths because generator-options and test-generators require different relative paths. | ||
const jsInstallStdout = cloneRepoToPath( | ||
"https://github.com/ScottLogic/openapi-forge-javascript", | ||
jsGeneratorLocation, | ||
".." | ||
); | ||
const tsInstallStdout = cloneRepoToPath( | ||
"https://github.com/ScottLogic/openapi-forge-typescript", | ||
`../${tsGeneratorLocation}`, | ||
"../openapi-forge" | ||
); | ||
|
||
// Smoke test generator-options command | ||
const generatorOptionsStdout = shell.exec( | ||
`node ./src/index.js generator-options ${jsGeneratorLocation}`, | ||
{ silent: true } | ||
).stdout; | ||
|
||
if (generatorOptionsStdout.includes("moduleFormat")) { | ||
console.log("generator-options command succeeded"); | ||
} else { | ||
console.error( | ||
"generator-options command failed. Expected moduleFormat to be an option in the JavaScript generator." | ||
); | ||
process.exitCode = 1; | ||
} | ||
|
||
// Smoke test test-generators command by comparing the current number of passing tests in the TS generator to the number passing on this PR | ||
const currentCommitName = shell.exec("git rev-parse HEAD", { silent: true }); | ||
const checkoutLogs1 = gitCheckout("master"); | ||
const previousRun = runTestGenerators(); | ||
|
||
const { passed: expectedPassed } = previousRun[tsGeneratorLocation]; | ||
|
||
const checkoutLogs2 = gitCheckout(currentCommitName); | ||
const testGeneratorsStdout = runTestGenerators(); | ||
|
||
const { scenarios, passed } = testGeneratorsStdout[tsGeneratorLocation]; | ||
|
||
if (scenarios > 0 && passed >= expectedPassed) { | ||
console.log("test-generators command succeeded"); | ||
} else { | ||
console.error( | ||
"test-generators command failed. Expected " + | ||
expectedPassed + | ||
" passes but there were only " + | ||
passed + | ||
" passes." | ||
); | ||
process.exitCode = 1; | ||
} | ||
|
||
// Smoke test forge command | ||
const tempFolder = "temp-csharp"; | ||
const forgeStdout = shell.exec( | ||
`node ./src/index.js forge https://petstore3.swagger.io/api/v3/openapi.json https://github.com/ScottLogic/openapi-forge-csharp.git -o ${tempFolder}`, | ||
{ silent: true } | ||
).stdout; | ||
if (forgeStdout.includes("SUCCESSFUL")) { | ||
console.log("forge command succeeded"); | ||
} else { | ||
console.error("forge command failed."); | ||
process.exitCode = 1; | ||
} | ||
|
||
// Clean up | ||
shell.rm("-rf", jsGeneratorLocation, `../${tsGeneratorLocation}`, tempFolder); | ||
|
||
fs.writeFileSync( | ||
`log.txt`, | ||
[ | ||
jsInstallStdout, | ||
tsInstallStdout, | ||
generatorOptionsStdout, | ||
"run on master:", | ||
checkoutLogs1, | ||
JSON.stringify(previousRun), | ||
"run on current branch:", | ||
checkoutLogs2, | ||
JSON.stringify(testGeneratorsStdout), | ||
forgeStdout, | ||
].join("\r\n") | ||
); |