diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 32be0e6..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - rules: { - 'prettier/prettier': ['error', {}, { usePrettierrc: true }], - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/ban-ts-comment': 'off' - }, - root: true, - env: { - browser: true, - node: true - } -} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9beada9 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run lint -- --fix + - run: npm run build + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: 🤖 linting with autofix + branch: ${{ github.head_ref }} + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + - uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - run: npm ci + - run: npm run build + - run: npm test diff --git a/__tests__/text.test.ts b/__tests__/text.test.ts new file mode 100644 index 0000000..e0179ad --- /dev/null +++ b/__tests__/text.test.ts @@ -0,0 +1,17 @@ +import { utf8Encode } from '../src/text' + +describe('text', () => { + describe('utf8Encode', () => { + test('encodes "a" properly', () => { + expect(utf8Encode('a')).toEqual('a') + }) + + test('encodes "\\a" properly', () => { + expect(utf8Encode('\\a')).toEqual('\\a') + }) + + test('encodes blank string properly', () => { + expect(utf8Encode('')).toEqual('') + }) + }) +}) diff --git a/jest.config.ts b/jest.config.ts index 5b0fa89..e16e17c 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -3,6 +3,9 @@ * https://jestjs.io/docs/configuration */ +import { pathsToModuleNameMapper } from 'ts-jest' +import { compilerOptions } from './tsconfig.json' + export default { // All imported modules in your tests should be mocked automatically // automock: false, @@ -13,8 +16,12 @@ export default { // The directory where Jest should store its cached dependency information // cacheDirectory: "/private/var/folders/39/wx5hr2ps64d83gpwscpz2jg80000gn/T/jest_dx", + preset: 'ts-jest', + testEnvironment: 'node', + + moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }), // Automatically clear mock calls, instances, contexts and results before every test - clearMocks: true, + clearMocks: true // Indicates whether the coverage information should be collected while executing the test // collectCoverage: false, @@ -192,4 +199,4 @@ export default { // Whether to use watchman for file crawling // watchman: true, -}; +} diff --git a/package-lock.json b/package-lock.json index 6388f85..ec841e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ "eslint-plugin-prettier": "^4.2.1", "jest": "^28.1.3", "prettier": "^2.7.1", + "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.7.4" } @@ -1721,6 +1722,18 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "2.x" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -3583,6 +3596,12 @@ "node": ">=8" } }, + "node_modules/lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -4418,6 +4437,64 @@ "node": ">=8.0" } }, + "node_modules/ts-jest": { + "version": "28.0.7", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-28.0.7.tgz", + "integrity": "sha512-wWXCSmTwBVmdvWrOpYhal79bDpioDy4rTT+0vyUnE3ZzM7LOAAGG9NXwzkEL/a516rQEgnMmS/WKP9jBPCVJyA==", + "dev": true, + "dependencies": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^28.0.0", + "json5": "^2.2.1", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "bin": { + "ts-jest": "cli.js" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0" + }, + "peerDependencies": { + "@babel/core": ">=7.0.0-beta.0 <8", + "@jest/types": "^28.0.0", + "babel-jest": "^28.0.0", + "jest": "^28.0.0", + "typescript": ">=4.3" + }, + "peerDependenciesMeta": { + "@babel/core": { + "optional": true + }, + "@jest/types": { + "optional": true + }, + "babel-jest": { + "optional": true + }, + "esbuild": { + "optional": true + } + } + }, + "node_modules/ts-jest/node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", @@ -6013,6 +6090,15 @@ "update-browserslist-db": "^1.0.5" } }, + "bs-logger": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/bs-logger/-/bs-logger-0.2.6.tgz", + "integrity": "sha512-pd8DCoxmbgc7hyPKOvxtqNcjYoOsABPQdcCUjGp3d42VR2CX1ORhk2A87oqqu5R1kk+76nsxZupkmyd+MVtCog==", + "dev": true, + "requires": { + "fast-json-stable-stringify": "2.x" + } + }, "bser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", @@ -7413,6 +7499,12 @@ "p-locate": "^4.1.0" } }, + "lodash.memoize": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", + "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", + "dev": true + }, "lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", @@ -8007,6 +8099,33 @@ "is-number": "^7.0.0" } }, + "ts-jest": { + "version": "28.0.7", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-28.0.7.tgz", + "integrity": "sha512-wWXCSmTwBVmdvWrOpYhal79bDpioDy4rTT+0vyUnE3ZzM7LOAAGG9NXwzkEL/a516rQEgnMmS/WKP9jBPCVJyA==", + "dev": true, + "requires": { + "bs-logger": "0.x", + "fast-json-stable-stringify": "2.x", + "jest-util": "^28.0.0", + "json5": "^2.2.1", + "lodash.memoize": "4.x", + "make-error": "1.x", + "semver": "7.x", + "yargs-parser": "^21.0.1" + }, + "dependencies": { + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "ts-node": { "version": "10.9.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", diff --git a/package.json b/package.json index 5fb695e..14b3c22 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,12 @@ "description": "A JavaScript client for communicating with PlanetScale Edge API.", "main": "dist/index.js", "types": "dist/index.d.js", + "files": [ + "dist" + ], + "engines": { + "node": ">=16" + }, "type": "module", "prettier": { "semi": false, @@ -18,7 +24,7 @@ "clean": "rm -rf dist/", "prebuild": "npm run clean", "build": "tsc", - "lint": "eslint .", + "lint": "eslint src/ __tests__/", "test": "jest" }, "repository": { @@ -50,7 +56,23 @@ "eslint-plugin-prettier": "^4.2.1", "jest": "^28.1.3", "prettier": "^2.7.1", + "ts-jest": "^28.0.7", "ts-node": "^10.9.1", "typescript": "^4.7.4" + }, + "eslintConfig": { + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "rules": { + "prettier/prettier": ["error", {}, { "usePrettierrc": true }], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/ban-ts-comment": "off" + }, + "root": true, + "env": { + "browser": true, + "node": true + } } } diff --git a/tsconfig.json b/tsconfig.json index dcc24f2..45122a2 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,10 @@ "outDir": "dist", "removeComments": true, "allowJs": true, - "moduleResolution": "node" - } + "moduleResolution": "node", + "paths": {}, + "esModuleInterop": true, + "resolveJsonModule": true + }, + "files": ["src/index.ts"] }