Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add action to test netlify functions (#51)
* Downgrade to Jest@27 ts-jest does not yet support Jest@28. Follow the issue here: <kulshekhar/ts-jest#3453> * Move cypress and netlify to optionalDep Begin general dep cleanup * Enforce unix-style endings * Add netlify-api-test GitHub action * Move aws-lambda to devDeps * Create test .env in CI
- Loading branch information
Showing
5 changed files
with
11,745 additions
and
11,675 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,28 @@ | ||
name: Simple Comment | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
test-netlify-functions: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js 16.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Build Netlify functions | ||
run: | | ||
npm install yarn@^1 --no-package-lock -g | ||
yarn --frozen-lockfile --production=false --ignore-optional | ||
yarn run build:netlify | ||
- name: Test Netlify functions | ||
run: | | ||
node ./scripts/createTestEnv.mjs | ||
yarn test |
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,8 +1,9 @@ | ||
{ | ||
"json.schemas": [ | ||
{ | ||
"fileMatch": ["simple-comment-api.json"], | ||
"url": "./src/schema/openapi.schema.json" | ||
} | ||
] | ||
} | ||
{ | ||
"json.schemas": [ | ||
{ | ||
"fileMatch": ["simple-comment-api.json"], | ||
"url": "./src/schema/openapi.schema.json" | ||
} | ||
], | ||
"files.eol": "\n" | ||
} |
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,34 @@ | ||
#!/usr/bin/env node | ||
|
||
import { existsSync, readFileSync, writeFileSync } from "fs" | ||
import { exit } from "process" | ||
|
||
const envExists = existsSync(`${process.cwd()}/.env`) | ||
|
||
if (envExists) { | ||
console.error("Error: file .env already exists"); | ||
exit(1); | ||
} | ||
|
||
const randomString = (length = 10, chars ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz", str = "" ) => { | ||
if (length === 0) return str; | ||
return randomString(length - 1, chars, str + chars[Math.floor(Math.random() * chars.length)]); | ||
} | ||
|
||
const exampleEnv = readFileSync(`${process.cwd()}/example.env`, "utf8") | ||
const newEnv = exampleEnv | ||
.replace(/\r/g, "\n") | ||
.split("\n") | ||
.map(l => l.trim()) | ||
.filter(l => !l.startsWith("#")) // eliminate comments | ||
.filter(l => l.length > 0) // eliminate blank lines | ||
.map(line => line.split("=")) | ||
.map(([key, value]) => /PASSWORD/.test(key) | /SECRET/.test(key) ? [key, randomString()] : [key, value]) // replace secrets | ||
.map( keyVal => keyVal.join("=")) // make it a string | ||
.join("\n"); | ||
|
||
writeFileSync(`${process.cwd()}/.env`, newEnv); | ||
|
||
console.info("Success: file .env created"); | ||
|
||
exit(0); |
Oops, something went wrong.