-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from bhollis/tests
Add tests for content type, github workflow
- Loading branch information
Showing
7 changed files
with
78 additions
and
4 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,26 @@ | ||
name: PR Build | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 20.x | ||
cache: yarn | ||
|
||
- name: Install | ||
run: yarn install --frozen-lockfile --prefer-offline | ||
|
||
- name: Lint | ||
run: yarn lint | ||
|
||
- name: Build | ||
run: yarn start |
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,7 +1,11 @@ | ||
#!/bin/bash -e | ||
|
||
rm -rf ts-out | ||
|
||
tsc | ||
|
||
node --test | ||
|
||
rm -rf build | ||
mkdir -p build | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { strict as assert } from "node:assert"; | ||
import test from "node:test"; | ||
import { isJSONContentType } from "./content-type.js"; | ||
|
||
const jsonContentTypes = [ | ||
"application/json", | ||
"application/hal+json", | ||
"application/jrd+json", | ||
"application/ld+json", | ||
"application/vnd.collection+json", | ||
"application/vnd.XYZ-v1+json", | ||
"application/json; charset=utf-8", | ||
"application/json; charset=utf-8", | ||
"application/hal+json; charset=utf-8", | ||
"application/vnd.collection+json; charset=utf-8", | ||
"application/json; charset=windows-1252", | ||
]; | ||
const notJsonContentTypes = ["text/html", "text/json", "text/text", ""]; | ||
|
||
for (const contentType of jsonContentTypes) { | ||
test(`correctly identifies ${contentType} as JSON`, () => { | ||
assert.ok(isJSONContentType(contentType)); | ||
}); | ||
} | ||
|
||
for (const contentType of notJsonContentTypes) { | ||
test(`correctly identifies ${contentType} as NOT JSON`, () => { | ||
assert.ok(!isJSONContentType(contentType)); | ||
}); | ||
} |
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,9 @@ | ||
const jsonContentType = /^application\/([\w!#$&.\-^+]+\+)?json($|;)/; | ||
|
||
/** | ||
* Look for JSON if the content type is "application/json", | ||
* or "application/whatever+json" or "application/json; charset=utf-8" | ||
*/ | ||
export function isJSONContentType(contentType: string) { | ||
return jsonContentType.test(contentType); | ||
} |
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