Skip to content

Commit

Permalink
Added Unit Tests, GitHub actions, fixed loop way
Browse files Browse the repository at this point in the history
  • Loading branch information
ponlawat-w committed Nov 25, 2023
1 parent 6efd30d commit 3dbcfda
Show file tree
Hide file tree
Showing 15 changed files with 2,736 additions and 123 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Pull Request Check
on:
pull_request:
branches:
- dev/*
- master
jobs:
unit-tests:
name: Unit Tests
uses: ./.github/workflows/unit-tests.yml
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish
on:
push:
branches: master
jobs:
unit-tests:
name: Unit Tests
uses: ./.github/workflows/unit-tests.yml
publish:
name: Publish
needs: unit-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- name: Get package.json
id: get-package
run: echo PACKAGE=$(cat ./package.json) >> $GITHUB_OUTPUT
- name: Get package version
id: get-package-version
run: echo VERSION="${{ fromJson(steps.get-package.outputs.PACKAGE).version }}" >> $GITHUB_OUTPUT
- name: Install
run: npm ci
- name: Build
run: npm run build
- name: Publish
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag
run: |
git config --global user.name "ponlawat-w"
git config --global user.email "[email protected]"
git tag -fa ${{ steps.get-package-version.outputs.VERSION }}
git push --force origin ${{ steps.get-package-version.outputs.VERSION }}
19 changes: 19 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Unit Tests
on: workflow_call
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install
run: npm ci
- name: Test
run: npm run test
51 changes: 1 addition & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,55 +110,6 @@ mao.addInteraction(interaction);

### Using as CDN

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/ol.css">
<style>
#map {
width: 100%;
height: 90vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script>
<script src="https://www.unpkg.com/ol-osmwaysnap/dist/webpack/index.js"></script>
<script lang="js">
const basemap = new ol.layer.Tile({ source: new ol.source.OSM() });
const targetFeaturesLayer = new ol.layer.Vector({
source: new ol.source.Vector(),
style: new ol.style.Style({
stroke: new ol.style.Stroke({
width: 4,
color: '#ff0000'
})
})
});
const map = new ol.Map({
target: 'map',
layers: [basemap, targetFeaturesLayer],
view: new ol.View({
center: [11018989, 2130015],
zoom: 16
})
});
const interaction = new OSMWaySnap.OSMWaySnap({
source: targetFeaturesLayer.getSource(),
maximumResolution: 5,
fetchBufferSize: 250,
overpassEndpointURL: 'https://...' // Choose one instance from https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances
});
map.addInteraction(interaction);
</script>
</body>
</html>
```
[HTML Example](./examples/index.html)

---
3 changes: 1 addition & 2 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@

<div id="status"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script>
<script src="../dist/webpack/index.js"></script>
<!-- <script src="https://www.unpkg.com/ol-osmwaysnap/dist/webpack/index.js"></script> -->
<script src="https://www.unpkg.com/ol-osmwaysnap/dist/bundle/index.js"></script>
<script lang="js">
const basemap = new ol.layer.Tile({ source: new ol.source.OSM() });

Expand Down
Loading

0 comments on commit 3dbcfda

Please sign in to comment.