Skip to content

Commit f6db2f6

Browse files
authored
feat: add TypeScript definitions (#256)
* feat: build TypeScript definitions and use esbuild for bundling Inspired by OpenLayers approach. * chore: switch from Neutrino (webpack) to esbuild for dev server * chore: use dataurl loader for SVG files, activate minify option for bundle * chore: watch forever to support Cypress CI tests * chore: upgrade Cypress * chore: use localhost for integration test to avoid CORS issues * chore: rewrite unit test to integration test * chore: remove unused Jest and update dependencies * chore: rename GitHub workflow and use Node.js 16 * chore: move config for tools to separate files * chore: update GitHub workflows * chore: fix Cypress timeout * chore: fix website * chore: run Cypress tests with oldest and newest supported Node.js release * chore: use dynamic Node.js test matrix * chore: fix typo * chore: fix LTS version selection
1 parent 614b27a commit f6db2f6

25 files changed

+1143
-8672
lines changed

.eslintrc.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"cypress/globals": true,
4+
"node": true,
5+
"browser": true,
6+
"es6": true
7+
},
8+
"extends": ["eslint-config-airbnb-base", "prettier"],
9+
"parserOptions": {
10+
"ecmaVersion": 2022
11+
},
12+
"plugins": ["cypress", "prettier"],
13+
"rules": {
14+
"prettier/prettier": "error",
15+
"arrow-body-style": "off",
16+
"import/no-named-as-default": "off",
17+
"import/no-named-as-default-member": "off"
18+
}
19+
}

.github/workflows/cypress.yml

+9-14
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@ on: [push]
55
jobs:
66
build:
77
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
# Test on oldest Node LTS and latest Node stable
11+
node: [lts/-1, current]
812
steps:
9-
- uses: actions/checkout@v1
13+
- uses: actions/checkout@v3
1014

11-
- uses: actions/setup-node@v1
15+
- uses: actions/setup-node@v3
1216
with:
13-
node-version: 16
17+
cache: yarn
18+
node-version: ${{ matrix.node }}
1419

15-
- name: Get yarn cache
16-
id: yarn-cache
17-
run: echo "::set-output name=dir::$(yarn cache dir)"
18-
19-
- uses: actions/cache@v1
20-
with:
21-
path: ${{ steps.yarn-cache.outputs.dir }}
22-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
23-
restore-keys: |
24-
${{ runner.os }}-yarn-
2520
- name: Install dependencies
26-
run: yarn install
21+
run: yarn install --frozen-lockfile
2722

2823
- name: Run and record Cypress tests
2924
run: yarn run cy:test

.github/workflows/lint.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: actions/setup-node@v3
17+
with:
18+
cache: yarn
19+
node-version: latest
20+
21+
- name: Install dependencies
22+
run: yarn install --frozen-lockfile
23+
24+
- name: Run linting
25+
run: yarn lint

.github/workflows/test.yml

-32
This file was deleted.

.lintstagedrc.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"(src|__mocks__)/**/*.js": ["eslint --fix", "prettier --write"],
3+
"package.json": [
4+
"fixpack --sortToTop name --sortToTop license --sortToTop description --sortToTop version --sortToTop author --sortToTop main --sortToTop module --sortToTop files --sortToTop proxy --sortToTop dependencies --sortToTop peerDependencies --sortToTop devDependencies --sortToTop resolutions --sortToTop scripts"
5+
],
6+
"src/**/*.{css,scss}": ["stylelint --fix"]
7+
}

.neutrinorc.js

-21
This file was deleted.

.nvmrc

-1
This file was deleted.

.prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"trailingComma": "all",
3+
"singleQuote": true
4+
}

.stylelintrc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["stylelint-config-standard"]
3+
}

config/tsconfig-build.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"target": "es2017" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
5+
"module": "es2020" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
6+
// "lib": [], /* Specify library files to be included in the compilation. */
7+
"allowJs": true /* Allow javascript files to be compiled. */,
8+
// "checkJs": true, /* Report errors in .js files. */
9+
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10+
"declaration": true /* Generates corresponding '.d.ts' file. */,
11+
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
12+
"sourceMap": false /* Generates corresponding '.map' file. */,
13+
// "outFile": "./", /* Concatenate and emit output to single file. */
14+
"outDir": "../build" /* Redirect output structure to the directory. */,
15+
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
16+
// "composite": true, /* Enable project compilation */
17+
// "removeComments": true, /* Do not emit comments to output. */
18+
// "noEmit": true, /* Do not emit outputs. */
19+
"importHelpers": false /* Import emit helpers from 'tslib'. */,
20+
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
21+
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
22+
23+
/* Strict Type-Checking Options */
24+
"strict": false /* Enable all strict type-checking options. */,
25+
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
26+
"strictNullChecks": true /* Enable strict null checks. */,
27+
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
28+
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
29+
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
30+
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
31+
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
32+
33+
/* Additional Checks */
34+
// "noUnusedLocals": true, /* Report errors on unused locals. */
35+
// "noUnusedParameters": true, /* Report errors on unused parameters. */
36+
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
37+
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
38+
39+
/* Module Resolution Options */
40+
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
41+
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
42+
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
43+
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
44+
// "typeRoots": [], /* List of folders to include type definitions from. */
45+
// "types": [], /* Type declaration files to be included in compilation. */
46+
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
47+
"esModuleInterop": false /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
48+
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
49+
50+
/* Source Map Options */
51+
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
52+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
53+
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
54+
"inlineSources": false /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */,
55+
"skipLibCheck": true
56+
/* Experimental Options */
57+
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
58+
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
59+
},
60+
"include": ["../src/**/*.js"],
61+
"exclude": []
62+
}

cypress.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from 'cypress';
2+
3+
export default defineConfig({
4+
projectId: 'f88nv7',
5+
e2e: {
6+
baseUrl: 'http://localhost:8000',
7+
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
8+
supportFile: false,
9+
},
10+
});

cypress.json

-4
This file was deleted.

cypress/e2e/control/draw.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('Draw control', () => {
2+
beforeEach(() => {
3+
cy.visit('/');
4+
});
5+
6+
it('should show draw control for points', () => {
7+
cy.get('.ole-control-draw')
8+
.first()
9+
.should('have.attr', 'title', 'Draw Point');
10+
});
11+
12+
it('should show draw control for lines', () => {
13+
cy.get('.ole-control-draw')
14+
.eq(1)
15+
.should('have.attr', 'title', 'Draw LineString');
16+
});
17+
18+
it('should show draw control for polygons', () => {
19+
cy.get('.ole-control-draw')
20+
.last()
21+
.should('have.attr', 'title', 'Draw Polygon');
22+
});
23+
});
File renamed without changes.

cypress/integration/control/draw.spec.js

-23
This file was deleted.

cypress/plugins/index.js

-22
This file was deleted.

0 commit comments

Comments
 (0)