Skip to content

Commit

Permalink
run tests on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
gmaclennan committed Sep 26, 2024
1 parent cddac24 commit 24c9e71
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Node.js Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm test
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "npm run lint && node --test",
"prepare": "husky",
"lint": "eslint ."
},
Expand Down
11 changes: 3 additions & 8 deletions test/download-write-read.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { validateStyleMin, migrate } from '@maplibre/maplibre-gl-style-spec'
import { validateStyleMin } from '@maplibre/maplibre-gl-style-spec'
import tempDir from 'temp-dir'

import assert from 'node:assert'
Expand All @@ -9,7 +9,7 @@ import path from 'node:path'
import { pipeline } from 'node:stream/promises'
import test from 'node:test'

import { download, Reader, StyleDownloader } from '../lib/index.js'
import { download, Reader } from '../lib/index.js'

const TEST_MAP_STYLE = 'https://demotiles.maplibre.org/style.json'
const TEST_MAP_AREA = /** @type {const} */ ([5.956, 45.818, 10.492, 47.808]) // Switzerland
Expand All @@ -32,17 +32,12 @@ test('Everything written can be read', async (t) => {
const smpReadStream = download({
styleUrl: TEST_MAP_STYLE,
bbox: [...TEST_MAP_AREA],
maxzoom: 10,
maxzoom: 5,
})
await pipeline(smpReadStream, fs.createWriteStream(smpFilePath))

const reader = new Reader(smpFilePath)
const upstream = new StyleDownloader(TEST_MAP_STYLE)

const smpStyle = await reader.getStyle()
assert.deepEqual(validateStyleMin(smpStyle), [], 'Style is valid')

const upstreamStyle = migrate(await upstream.getStyle())

assert.deepStrictEqual(smpStyle, upstreamStyle)
})

0 comments on commit 24c9e71

Please sign in to comment.