This repository has been archived by the owner on Apr 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce Function File Contract earlier (#27)
- Loading branch information
1 parent
daf2b41
commit 1f79e7a
Showing
8 changed files
with
139 additions
and
8 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 |
---|---|---|
|
@@ -12,7 +12,7 @@ _**Note:** The examples below use version `0.1.0` of `deno-slack-builder`; check | |
|
||
In a directory that contains a valid manifest file (`manifest.json`, `manifest.js`, or `manifest.ts`), run the following: | ||
|
||
``` | ||
```bash | ||
deno run --allow-write --allow-read "https://deno.land/x/[email protected]/mod.ts" | ||
``` | ||
|
||
|
@@ -31,12 +31,14 @@ The top level `mod.ts` file is executed as a Deno program, and takes up to three | |
### Example Usage | ||
|
||
**Only generate a valid Run On Slack manifest file:** | ||
``` | ||
|
||
```bash | ||
deno run --allow-write --allow-read "https://deno.land/x/[email protected]/mod.ts" --manifest | ||
``` | ||
|
||
**Generate a Run On Slack project from a /src directory:** | ||
``` | ||
|
||
```bash | ||
deno run --allow-write --allow-read "https://deno.land/x/[email protected]/mod.ts" --source src | ||
``` | ||
|
||
|
@@ -55,6 +57,7 @@ Allows for flexibility with how you define your manifest. | |
* If no `manifest.ts` exists, looks for a `manifest.js` file, and follows the same logic as `manifest.ts` does. | ||
|
||
## Function Bundling | ||
|
||
* For each entry in the `functions` where `remote_environment=slack` it looks for a `source_file` property, which should be a relative path to the corresponding function file. This is then bundled for the Run on Slack Deno runtime. The `reverse` function defined below indicates there should be a corresponding function file in the project located at `functions/reverse.ts`. | ||
|
||
```json | ||
|
@@ -89,11 +92,15 @@ Allows for flexibility with how you define your manifest. | |
|
||
If you make changes to this repo, or just want to make sure things are working as desired, you can run: | ||
|
||
deno task test | ||
```bash | ||
deno task test | ||
``` | ||
|
||
To get a full test coverage report, run: | ||
|
||
deno task coverage | ||
```bash | ||
deno task coverage | ||
``` | ||
|
||
--- | ||
|
||
|
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { | ||
assertEquals, | ||
assertExists, | ||
assertRejects, | ||
} from "https://deno.land/[email protected]/testing/asserts.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default () => { | ||
console.log("this is my slack function"); | ||
}; |
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 const func = () => { | ||
console.log("this is my slack function"); | ||
}; |
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 @@ | ||
export default "hello"; |
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 |
---|---|---|
@@ -1,6 +1,107 @@ | ||
import { validateAndCreateFunctions } from "../functions.ts"; | ||
import { assertExists } from "../dev_deps.ts"; | ||
import { assertEquals, assertExists, assertRejects } from "../dev_deps.ts"; | ||
import { Options } from "../types.ts"; | ||
|
||
Deno.test("validateAndCreateFunctions", () => { | ||
assertExists(validateAndCreateFunctions); | ||
}); | ||
|
||
Deno.test("validateAndCreateFunctions should not throw an exception when fed a function file that has a default export", async () => { | ||
const captured_log: string[] = []; | ||
const options: Options = { | ||
manifestOnly: true, | ||
workingDirectory: Deno.cwd(), | ||
log: (x) => { | ||
captured_log.push(x); | ||
}, | ||
}; | ||
const manifest = { | ||
"functions": { | ||
"test_function": { | ||
"title": "Test function", | ||
"description": "this is a test", | ||
"source_file": "src/tests/functions/test_function_file.ts", | ||
"input_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
"output_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
await validateAndCreateFunctions( | ||
options, | ||
manifest, | ||
); | ||
assertEquals("", captured_log.join("")); | ||
}); | ||
|
||
Deno.test("Function files with no default export should get an error", async () => { | ||
const captured_log: string[] = []; | ||
const options: Options = { | ||
manifestOnly: true, | ||
workingDirectory: Deno.cwd(), | ||
log: (x) => { | ||
captured_log.push(x); | ||
}, | ||
}; | ||
const manifest = { | ||
"functions": { | ||
"test_function": { | ||
"title": "Test function", | ||
"description": "this is a test", | ||
"source_file": "src/tests/functions/test_function_no_export_file.ts", | ||
"input_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
"output_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
await assertRejects( | ||
() => validateAndCreateFunctions(options, manifest), | ||
Error, | ||
"default export handler", | ||
); | ||
}); | ||
|
||
Deno.test("Function files not exporting a function should get an error", async () => { | ||
const captured_log: string[] = []; | ||
const options: Options = { | ||
manifestOnly: true, | ||
workingDirectory: Deno.cwd(), | ||
log: (x) => { | ||
captured_log.push(x); | ||
}, | ||
}; | ||
const manifest = { | ||
"functions": { | ||
"test_function": { | ||
"title": "Test function", | ||
"description": "this is a test", | ||
"source_file": "src/tests/functions/test_function_not_function_file.ts", | ||
"input_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
"output_parameters": { | ||
"required": [], | ||
"properties": {}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
await assertRejects( | ||
() => validateAndCreateFunctions(options, manifest), | ||
Error, | ||
"default export handler", | ||
); | ||
}); |