Skip to content

Commit

Permalink
Merge pull request #87 from Imageomics/fix-npm-build
Browse files Browse the repository at this point in the history
Fix npm build and automate testing
  • Loading branch information
johnbradley authored Feb 15, 2024
2 parents db3aa99 + 8c99a4c commit 28b847d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/node-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Python package

on: [push]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- run: npm install
working-directory: ./andromeda-ui
- run: npm run build
working-directory: ./andromeda-ui
- run: npm run test
working-directory: ./andromeda-ui

3 changes: 1 addition & 2 deletions andromeda-ui/components/DataExplorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface DataExplorerProps {
weights: any | undefined;
datasetID: string | undefined;
columnSettings: any;
columnDetails: any;
drFunc: any;
rdrFunc: any;
onClickBack: any;
Expand All @@ -28,7 +27,7 @@ interface DataExplorerProps {

export default function DataExplorer(props: DataExplorerProps) {
const { images, setImageData, pointScaling, setPointScaling,
weights, datasetID, columnSettings, columnDetails,
weights, datasetID, columnSettings,
drFunc, rdrFunc, onClickBack } = props;
const [imageSize, setImageSize] = useState<number>(DEFAULT_IMAGE_SIZE);
const [showLabel, setShowLabel] = useState<boolean>(true);
Expand Down
10 changes: 6 additions & 4 deletions andromeda-ui/tests/backend/observations.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { makeObservationURL, fetchObservations } from "../../backend/observations";
import fetchMock from 'fetch-mock';

jest.mock('next/config', () => () => ({
publicRuntimeConfig: {
Expand Down Expand Up @@ -33,8 +32,11 @@ test("fetchObservations returns JSON result of observations", async () => {
"data": [{"label": "p1"}],
"warnings": ["some_warning"]
}
fetchMock.get('https://example.com/api/inaturalist/bob?format=json&add_sat_rgb_data=false&add_landcover_data=false', payload);
const results = await fetchObservations("bob", false, false);
jest.spyOn(global, "fetch").mockImplementation(
jest.fn(
() => Promise.resolve({ ok: true, json: () => Promise.resolve(payload),
}),
) as jest.Mock );
const results = await fetchObservations("bob", false, false, 10);
expect(results).toStrictEqual(payload);
fetchMock.restore();
});
9 changes: 5 additions & 4 deletions andromeda-ui/tests/backend/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { apiURL, fetch_json } from "../../backend/util";
import fetchMock from 'fetch-mock';

jest.mock('next/config', () => () => ({
publicRuntimeConfig: {
Expand All @@ -14,9 +13,11 @@ test("apiURL creates a URL for a prefix", () => {

test("fetch_json calls fetch", async () => {
const url = "https://example.com/api/dataset/123";
fetchMock.get(url, {
"data": 123
});
jest.spyOn(global, "fetch").mockImplementation(
jest.fn(
() => Promise.resolve({ ok: true, json: () => Promise.resolve({"data": 123}),
}),
) as jest.Mock );
const result = await fetch_json(url, { method: "GET"});
expect(result).toStrictEqual({
"data": 123
Expand Down

0 comments on commit 28b847d

Please sign in to comment.