forked from Petah/2d-visibility
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rename repo, add github actions, add unit tests
- Loading branch information
1 parent
8789c39
commit e3cd0e0
Showing
8 changed files
with
106 additions
and
8 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,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 }} |
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,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 |
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,4 +1,4 @@ | ||
node_modules | ||
dist | ||
*.sublime-project | ||
*.sublime-workspace | ||
bundle.js | ||
*.sublime-workspace |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,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)], | ||
]); | ||
}); | ||
}); |
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