Skip to content

Commit 20f3006

Browse files
committed
fix tests, dev command, cleanup
1 parent 204d989 commit 20f3006

21 files changed

+60
-75
lines changed

.babelrc

Lines changed: 0 additions & 10 deletions
This file was deleted.

.flowconfig

Lines changed: 0 additions & 10 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.
File renamed without changes.

netlify.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
functions = "handler"
33
command = "npm run download && npm run build"
44
publish = "public/"
5-
6-
[watch]
7-
functions = "handler"
5+
[dev]
86
command = "npm run download && npm run build"
97
publish = "public/"
8+
functions = "handler"
109
[[headers]]
1110
for = "/*"
1211
[headers.values]

package-lock.json

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@
2020
"type": "module",
2121
"scripts": {
2222
"postinstall": "npm run download && npm run build",
23-
"watch": "netlify dev",
23+
"dev": "npm run download && netlify dev -c 'tsc --watch'",
2424
"start": "netlify build",
2525
"test": "npm run lint && npm run check && npm run test:only",
26-
"test:only": "vitest run --config ./vitest.config.ts",
26+
"test:only": "vitest run",
2727
"lint": "eslint src/** handler/**",
2828
"lint:fix": "eslint --fix src handler/**",
2929
"check": "tsc --noEmit",
30-
"build": "rimraf lib && tsc ",
31-
"download": "node scripts/download.js cache/data.json",
30+
"build": "rimraf lib && tsc",
31+
"build:watch": "tsc --watch",
32+
"download": "node scripts/download.mjs cache/data.json",
3233
"serve-public": "node scripts/serve-public",
3334
"prettier": "prettier --write 'src/**/*.js'",
3435
"print-schema": "node scripts/print-schema.js",
@@ -54,7 +55,7 @@
5455
"typescript": "^5.1.6",
5556
"vitest": "^0.34.1"
5657
},
57-
"resolutions": {
58+
"overrides": {
5859
"graphql": "^16.7.1"
5960
}
6061
}

scripts/download.js renamed to scripts/download.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { URL } from 'url';
1010
import { Agent } from 'https';
1111
import { existsSync, writeFileSync } from 'fs';
1212
import fetch from 'isomorphic-fetch';
13-
import { swapiPath } from '../src/schema/constants';
13+
import { swapiPath } from '../src/schema/constants.mjs';
1414

1515
const resources = [
1616
'people',

src/api/local.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
*/
1010

11-
import { DataResult } from '../types.js';
11+
import { DataResult, ResultItem } from '../types.js';
1212

1313

1414
/**
@@ -21,13 +21,13 @@ export async function getFromLocalUrl(
2121
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2222
// @ts-ignore
2323
const swapiData = (await import('../../cache/data.json')).default
24-
const text = swapiData[url] as DataResult;
24+
const text = swapiData[url] as ResultItem;
2525
if (!text) {
2626
throw new Error(`No entry in local cache for ${url}`);
2727
}
2828
if (process.env.NODE_ENV !== 'test') {
2929
// eslint-disable-next-line no-console
3030
console.log(`Hit the local cache for ${url}.`);
3131
}
32-
return text as DataResult;
32+
return text as ResultItem;
3333
}

src/schema/__tests__/schema.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ import { swapi } from './swapi';
1212
describe('Schema', () => {
1313
it('Gets an error when ID is omitted', async () => {
1414
const query = '{ species { name } }';
15-
const result = await swapi(query);
15+
const result = await swapi(query, false);
1616
expect(result.errors.length).toBe(1);
1717
expect(result.errors[0].message).toBe('must provide id or speciesID');
1818
expect(result.data).toMatchObject({ species: null });
1919
});
2020

2121
it('Gets an error when global ID is invalid', async () => {
2222
const query = '{ species(id: "notanid") { name } }';
23-
const result = await swapi(query);
23+
const result = await swapi(query, false);
2424
expect(result.errors.length).toBe(1);
2525
expect(result.errors[0].message).toEqual(
26-
expect.stringContaining('No entry in local cache for'),
26+
expect.stringContaining('No valid ID extracted from notanid'),
2727
);
2828
expect(result.data).toMatchObject({ species: null });
2929
});

0 commit comments

Comments
 (0)