Skip to content
Merged

Tests #294

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2
3 changes: 0 additions & 3 deletions .eslintignore

This file was deleted.

41 changes: 0 additions & 41 deletions .eslintrc.cjs

This file was deleted.

57 changes: 24 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,27 @@
name: CI
on:
push:
branches:
- master
pull_request:
branches:
- master

push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 20 ]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
# - name: Install Playwright Browsers
# run: npx playwright install --with-deps
- name: Run tests
run: npm test
# - uses: actions/upload-artifact@v4
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
test:
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
matrix:
node: [24]
name: Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Run tests
run: npm test
36 changes: 18 additions & 18 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: npm-publish
on:
release:
types: [created]
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run build
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "24.x"
registry-url: "https://registry.npmjs.org"
- run: npm ci
- run: npm run build
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Empty file removed .npmignore
Empty file.
5 changes: 0 additions & 5 deletions .prettierrc

This file was deleted.

15 changes: 0 additions & 15 deletions .swcrc

This file was deleted.

78 changes: 70 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,78 @@
{
"editor.bracketPairColorization.enabled": true,
"editor.rulers": [100, 120],
"editor.formatOnPaste": false,
"editor.guides.bracketPairs": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": ["source.fixAll.eslint"],
"eslint.validate": ["javascript", "javascriptreact", "typescript"],
"typescript.tsdk": "./node_modules/typescript/lib",
"svg.preview.background": "editor",
"eslint.useFlatConfig": true,
"editor.bracketPairColorization.enabled": true,
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.updateImportsOnFileMove.enabled": "always",
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true,
"**/*.code-search": true
},

// Disable the default formatter, use eslint instead
"prettier.enable": false,
"editor.formatOnSave": false,

// Auto fix
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
"source.organizeImports": "never"
},

// Silent the stylistic rules in you IDE, but still auto fix them
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],

// Enable eslint for all supported languages
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"jsonc",
"yaml",
"toml"
],

"[shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[ignore]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[shellscript]": {
"[dockerfile]": {
"editor.defaultFormatter": "ms-azuretools.vscode-docker"
},
"[css]": {
"editor.wordWrap": "off"
},
"[properties]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": "never"
},
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[yaml]": {
"editor.autoIndent": "advanced",
"editor.defaultFormatter": "redhat.vscode-yaml"
}
}
47 changes: 47 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { node, jsonc, common, GLOB_TS, disabled, typescript, formatters, GLOB_TESTS } from 'eslint-config-jwalker'

/** @type {import('eslint').Linter.Config[]} */
export default [
...common,
...node,
...typescript,
...jsonc,
...formatters,
...disabled,
{ ignores: ['examples/**/*'] },
{
rules: {},
},
{
files: [GLOB_TS],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',

'no-duplicate-imports': 'off',
'no-restricted-globals': 'off',
'no-unused-vars': 'off',

'unicorn/prefer-single-call': 'off',
},
},
{
files: Array.from(GLOB_TESTS),
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-ts-expect-error': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',

'max-statements': 'off',
'max-statements-per-line': 'off',
'no-console': 'off',
'no-empty-function': 'off',
'no-undef': 'off',
},
},
]
61 changes: 61 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Examples

This directory contains example projects demonstrating how to use `ol-contextmenu` in different scenarios.

## Available Examples

### 1. CDN Example (`contextmenu.html`)

**Best for**: Quick start, no build tools required

This example shows how to use `ol-contextmenu` with CDN-hosted libraries. It demonstrates:
- Basic menu item setup with callbacks
- Menu items with icons
- Submenus (nested menu items)
- Separators
- Dynamic menu updates based on context
- Feature detection at click location
- Custom data propagation to callbacks

**How to run**:
1. Open `contextmenu.html` in a web browser
2. Right-click anywhere on the map to see the context menu
3. Right-click on a marker to see a different menu

**Key concepts demonstrated**:
- Creating a context menu with custom items
- Using the `open` event to dynamically change menu items
- Detecting features at the click location
- Passing custom data to callback functions

### 2. Webpack Example (`my-project-with-webpack/`)

**Best for**: Projects using Webpack as a bundler

This example demonstrates how to integrate `ol-contextmenu` in a Webpack-based project with ES6 modules. It shows:
- ES6 module imports
- Multi-level nested submenus
- Using `defaultItems` option
- `beforeopen` event handling
- CSS imports with Webpack

See the [Webpack example README](./my-project-with-webpack/README.md) for detailed setup instructions.

### 3. Vite Example (`my-project-with-vite/`)

**Best for**: Modern projects using Vite with TypeScript

This example shows how to use `ol-contextmenu` in a Vite + TypeScript project. It demonstrates:
- TypeScript type imports
- Type-safe callback functions
- Module bundling with Vite
- CSS imports with Vite

See the [Vite example README](./my-project-with-vite/README.md) for detailed setup instructions.

## Next Steps

- Check out the [main README](../README.md) for complete API documentation
- Explore the source code to see how different features are implemented
- Try modifying the examples to add your own menu items and callbacks

Loading