Skip to content

Commit

Permalink
chore: rename repo, add github actions, add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frederic-schwarz committed Jan 11, 2024
1 parent 8789c39 commit e3cd0e0
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 8 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# adopted from https://github.com/archilogic-com/actions/blob/main/.github/workflows/publish-npm-package.yml
name: Publish NPM package
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/
- run: npm ci
env:
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_TOKEN_READONLY }}

- run: npm run typecheck && npm run test
- id: get-dist-tag
uses: actions/github-script@v6
with:
script: |
const { parse } = require('semver')
const { version } = require('./package.json')
const [numberOrTag] = parse(version).prerelease
const isTag = typeof numberOrTag === 'string'
const distTag = isTag ? numberOrTag : 'latest'
core.setOutput('dist-tag', distTag)
- run: npm run build && npm publish --tag ${{steps.get-dist-tag.outputs.dist-tag}}
env:
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/tests.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Type check and tests

on:
push:
branches:
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Setup npmrc
run: npm config set //registry.npmjs.org/:_authToken=${{secrets.CI_NPM_TOKEN_READONLY}}
- run: npm ci
- run: npm run typecheck
- run: npm run build && npm run test
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
dist
*.sublime-project
*.sublime-workspace
bundle.js
*.sublime-workspace
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "2d-visibility-demo-typescript",
"name": "@archilogic/2d-visibility",
"version": "1.0.0",
"description": "",
"keywords": [],
Expand All @@ -9,6 +9,9 @@
},
{
"name": "David Neilsen"
},
{
"name": "Frederic Schwarz"
}
],
"license": "MIT",
Expand All @@ -31,6 +34,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "tslint --project tsconfig.json"
"test": "vitest --run",
"typecheck": "vue-tsc --noEmit"
}
}
29 changes: 29 additions & 0 deletions src/__tests__/visibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { loadMap } from "../load-map";
import { Point, PolygonWithHoles } from "../types";
import { calculateVisibility } from "../visibility";

describe("when computing visibility in an L shaped polygon", () => {
const polygon: PolygonWithHoles = [
[
[0, 0],
[200, 0],
[200, 200],
[400, 200],
[400, 300],
[0, 300],
],
];

const point = new Point(100, 100);
const { endPoints } = loadMap(polygon, point);
const visibility = calculateVisibility(point, endPoints);
it("creates creates a cut off shape", () => {
expect(visibility).toMatchObject([
[new Point(0, 300), new Point(0, 0)],
[new Point(0, 0), new Point(200, 0)],
[new Point(200, 0), new Point(200, 200)],
[new Point(200, 200), new Point(200, 200)],
[new Point(300, 300), new Point(0, 300)],
]);
});
});
6 changes: 5 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"noEmitHelpers": true
"noEmitHelpers": true,
"types": [
"vitest/globals"
],
"skipLibCheck": true,
},
"include": [
"./src/**/*.ts"
Expand Down
1 change: 0 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import dts from "vite-plugin-dts";

export default defineConfig({
test: {
environment: "jsdom",
globals: true,
},
plugins: [dts({ rollupTypes: true })],
Expand Down

0 comments on commit e3cd0e0

Please sign in to comment.