-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests for new runtimes: [Bun](https://bun.sh/), [Deno](https://deno.land/) and the [Edge runtime](https://edge-runtime.vercel.sh/). I wanted to add tests for node16 ESM modes as well as Cloudflare Workers and react-native maybe. But I'm out of time and it's best to get in what we have and follow up with new PRs. The Deno test is expected [to keep failing](https://github.com/sanity-io/client/runs/7849905824?check_suite_focus=true#step:5:201) until [`get-it` gets a similar](https://github.com/sanity-io/get-it/blob/7873e3fb4f38c21fe91f727f65acca250bc6c5f0/package.json#L9-L23) fix as #24
- Loading branch information
Showing
14 changed files
with
15,240 additions
and
31 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 |
---|---|---|
|
@@ -11,9 +11,7 @@ | |
], | ||
"env": { | ||
"test": { | ||
"plugins": [ | ||
"istanbul" | ||
] | ||
"plugins": ["istanbul"] | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ lib | |
umd | ||
coverage | ||
.nyc_output | ||
runtimes/deno |
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,106 @@ | ||
name: CI | ||
|
||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [12.x, 14.x, 16.x, 18.x] | ||
name: node ${{ matrix.node-version }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm install | ||
- run: npm test | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run prepublishOnly | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: build-output | ||
path: | | ||
lib/ | ||
umd/ | ||
prod-deps: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- id: prod-deps | ||
uses: actions/cache@v3 | ||
with: | ||
path: ./node_modules | ||
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | ||
- if: steps.prod-deps.outputs.cache-hit != 'true' | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
- if: steps.prod-deps.outputs.cache-hit != 'true' | ||
run: npm install --omit=dev --ignore-scripts | ||
|
||
edge-runtime: | ||
runs-on: ubuntu-latest | ||
needs: [build, prod-deps] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: lts/* | ||
cache: 'npm' | ||
cache-dependency-path: runtimes/edge/package-lock.json | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ./node_modules | ||
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | ||
- uses: actions/download-artifact@v3 | ||
with: | ||
name: build-output | ||
- run: npm ci | ||
working-directory: runtimes/edge | ||
- run: npm test | ||
working-directory: runtimes/edge | ||
|
||
## Temporarily disabled until we can get all downstream dependencies working with deno | ||
# deno-runtime: | ||
# runs-on: ubuntu-latest | ||
# needs: [build, prod-deps] | ||
# steps: | ||
# - uses: actions/checkout@v3 | ||
# - uses: actions/cache@v3 | ||
# with: | ||
# path: ./node_modules | ||
# key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | ||
# - uses: denoland/setup-deno@v1 | ||
# - name: deno test | ||
# run: | | ||
# deno fmt --check | ||
# deno lint | ||
# deno check *.ts | ||
# deno test --allow-net | ||
# working-directory: runtimes/deno | ||
|
||
bun-runtime: | ||
runs-on: ubuntu-latest | ||
needs: [build, prod-deps] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ./node_modules | ||
key: prod-deps-${{ runner.os }}-${{ hashFiles('package-lock.json') }} | ||
- uses: antongolub/action-setup-bun@v1 | ||
- run: bun wiptest | ||
working-directory: runtimes/bun |
This file was deleted.
Oops, something went wrong.
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,4 @@ | ||
{ | ||
"deno.enable": true, | ||
"deno.enablePaths": ["runtimes/deno"] | ||
} |
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,24 @@ | ||
import createClient from '../..' | ||
import {expect, test} from 'bun:test' | ||
|
||
const projectId = '81pocpw8' | ||
const dataset = 'production' | ||
const apiVersion = 'v2021-03-25' | ||
const query = /* groq */ `count(*[studioVersion == 3])` | ||
|
||
// Ensure the runtime is supposed to be able to run this query correctly | ||
test('native fetch', async () => { | ||
const res = await fetch( | ||
`https://${projectId}.apicdn.sanity.io/${apiVersion}/data/query/${dataset}?query=${encodeURIComponent( | ||
query | ||
)}` | ||
) | ||
const {result: data} = await res.json() | ||
expect(Number.isInteger(data)).toBe(true) | ||
}) | ||
|
||
test('@sanity/client', async () => { | ||
const client = createClient({projectId, dataset, apiVersion, useCdn: true}) | ||
const data = await client.fetch(query) | ||
expect(Number.isInteger(data)).toBe(true) | ||
}) |
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,31 @@ | ||
import { assert } from "https://deno.land/std@0.152.0/testing/asserts.ts"; | ||
import { createClient } from "./deps.ts"; | ||
|
||
const projectId = "81pocpw8"; | ||
const dataset = "production"; | ||
const apiVersion = "v2021-03-25"; | ||
const query = /* groq */ `count(*[studioVersion == 3])`; | ||
|
||
// Ensure the runtime is supposed to be able to run this query correctly | ||
Deno.test("native fetch", async () => { | ||
const res = await fetch( | ||
`https://${projectId}.apicdn.sanity.io/${apiVersion}/data/query/${dataset}?query=${ | ||
encodeURIComponent( | ||
query, | ||
) | ||
}`, | ||
); | ||
const { result: data } = await res.json(); | ||
assert(Number.isInteger(data)); | ||
}); | ||
|
||
Deno.test("@sanity/client fetch", async () => { | ||
const client = createClient({ | ||
projectId, | ||
dataset, | ||
apiVersion, | ||
useCdn: true, | ||
}); | ||
const data = await client.fetch(query); | ||
assert(Number.isInteger(data)); | ||
}); |
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,4 @@ | ||
// @TODO replace with a local path once we start exporting ESM | ||
// import createClient from '../../dist/sanityClient.browser.mjs' | ||
import createClient from "https://esm.sh/@sanity/client"; | ||
export { createClient }; |
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,25 @@ | ||
const {expect, test} = require('@jest/globals') | ||
const createClient = require('@sanity/client') | ||
|
||
const projectId = '81pocpw8' | ||
const dataset = 'production' | ||
const apiVersion = 'v2021-03-25' | ||
const query = /* groq */ `count(*[studioVersion == 3])` | ||
|
||
// Ensure the runtime is supposed to be able to run this query correctly | ||
test('native fetch', async () => { | ||
expect.assertions(1) | ||
const res = await fetch( | ||
`https://${projectId}.apicdn.sanity.io/${apiVersion}/data/query/${dataset}?query=${encodeURIComponent( | ||
query | ||
)}` | ||
) | ||
const {result: data} = await res.json() | ||
expect(data).toEqual(expect.any(Number)) | ||
}) | ||
test('@sanity/client', async () => { | ||
expect.assertions(1) | ||
const client = createClient({projectId, dataset, apiVersion, useCdn: true}) | ||
const data = await client.fetch(query) | ||
expect(data).toEqual(expect.any(Number)) | ||
}) |
Oops, something went wrong.