-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests that include all files * adding mod tests * improve accuracy of test coverage * improve snapshot tests * Delete type_utils_test.ts * Improve the builtin generation tests * revert file name changes * clean up * Add tests
- Loading branch information
1 parent
e4f2538
commit 94858bf
Showing
10 changed files
with
111 additions
and
24 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 |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
} | ||
}, | ||
"tasks": { | ||
"test": "deno fmt --check && deno lint && deno bundle src/mod.ts && deno test --allow-read --parallel src/ tests/", | ||
"test": "deno fmt --check && deno lint && deno bundle src/mod.ts && deno test --allow-read --allow-run --parallel src/ tests/", | ||
"coverage": "rm -rf .coverage && deno test --reporter=dot --parallel --allow-read --coverage=.coverage src/ && deno coverage --exclude=fixtures --exclude=_test --lcov --output=lcov.info .coverage && deno run --allow-read https://deno.land/x/[email protected]/cli.ts" | ||
}, | ||
"lock": false | ||
|
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,3 @@ | ||
export { SlackFunctionTemplate } from "./template_function.ts"; | ||
export { SlackTestFunctionTemplate } from "./test_template.ts"; | ||
export { SlackFunctionModTemplate } from "./template_mod.ts"; |
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
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
File renamed without changes.
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
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
67 changes: 67 additions & 0 deletions
67
tests/integration/schema/slack/functions/_scripts/write_function_files_test.ts
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,67 @@ | ||
import { | ||
assertEquals, | ||
assertExists, | ||
mock, | ||
} from "../../../../../../src/dev_deps.ts"; | ||
import { _internals } from "../../../../../../src/schema/slack/functions/_scripts/src/write_function_files.ts"; | ||
import { getSlackFunctions } from "../../../../../../src/schema/slack/functions/_scripts/src/utils.ts"; | ||
|
||
Deno.test(`write_function_files.ts ${_internals.main.name} function generates valid typescript`, async () => { | ||
const getSlackFunctionsStub = mock.stub( | ||
_internals, | ||
"getSlackFunctions", | ||
( | ||
functionsPayloadPath = | ||
"src/schema/slack/functions/_scripts/src/test/data/function.json", | ||
) => { | ||
return getSlackFunctions( | ||
functionsPayloadPath, | ||
); | ||
}, | ||
); | ||
|
||
const outputs: Record<string, string> = {}; | ||
|
||
const writeTextFileStub = mock.stub( | ||
_internals, | ||
"writeTextFile", | ||
// deno-lint-ignore require-await | ||
async (path, data) => { | ||
outputs[path] = data; | ||
}, | ||
); | ||
|
||
try { | ||
await _internals.main(); | ||
mock.assertSpyCalls(writeTextFileStub, 3); | ||
mock.assertSpyCalls(getSlackFunctionsStub, 1); | ||
|
||
const generatedContent = outputs["../send_message.ts"]; | ||
assertExists(generatedContent); | ||
|
||
const command = new Deno.Command(Deno.execPath(), { | ||
cwd: `${Deno.cwd()}/src/schema/slack/functions/`, | ||
args: [ | ||
"eval", | ||
generatedContent, | ||
], | ||
}); | ||
const { code, stdout, stderr } = await command.output(); | ||
const textDecoder = new TextDecoder(); | ||
|
||
assertEquals( | ||
textDecoder.decode(stderr), | ||
"", | ||
"The generated TypeScript content is not valid", | ||
); | ||
assertEquals( | ||
textDecoder.decode(stdout), | ||
"", | ||
"The generated TypeScript should not print to the console", | ||
); | ||
assertEquals(code, 0); | ||
} finally { | ||
writeTextFileStub.restore(); | ||
getSlackFunctionsStub.restore(); | ||
} | ||
}); |