Skip to content

Commit

Permalink
chore: set up ci
Browse files Browse the repository at this point in the history
  • Loading branch information
timursaurus committed Mar 26, 2023
1 parent 743836b commit ae92cb5
Show file tree
Hide file tree
Showing 8 changed files with 2,680 additions and 58 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode
node_modules
*.log*
dist
coverage
.profile
.idea
.eslintcache
100 changes: 100 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"parser": "@typescript-eslint/parser",
"extends": [
"prettier",
"standard",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"plugins": ["@typescript-eslint"],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"node": { "extensions": [".js", ".mjs", ".cjs"] },
"typescript": {}
}
},
"rules": {
// Disable formatting rules
"semi": 0,
"quotes": 0,
"indent": 0,
"space-before-function-paren": 0,
"arrow-parens": 0,
"comma-dangle": 0,
"keyword-spacing": 0,
"no-multiple-empty-lines": 0,
"no-trailing-spaces": 0,
"unicorn/number-literal-case": 0,
"unicorn/template-indent": 0,
"generator-star-spacing": 0,
"space-infix-ops": 0,
"comma-spacing": 0,
"brace-style": 0,
"space-in-parens": 0,
"space-before-blocks": 0,
"semi-spacing": 0,
"object-property-newline": 0,
"no-multi-spaces": 0,
"key-spacing": 0,
"eol-last": 0,
"func-call-spacing": 0,
"comma-style": 0,

// Disable some unnecessary or conflicting rules
"no-use-before-define": "off",
"unicorn/prevent-abbreviations": 0,
"unicorn/no-await-expression-member": 0,
"unicorn/no-useless-undefined": 0,
"unicorn/no-array-push-push": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/ban-ts-comment": 0,
"@typescript-eslint/no-empty-interface": 0,

// Enforce import order
"import/order": "error",

// Imports should come first
"import/first": "error",

// Other import rules
"import/no-mutable-exports": "error",

// Allow unresolved imports
"import/no-unresolved": "off",

// Prefer const over let
"prefer-const": [
"error",
{
"destructuring": "any",
"ignoreReadBeforeAssign": false
}
],

// No single if in an "else" block
"no-lonely-if": "error",

// Force curly braces for control flow,
// including if blocks with a single statement
"curly": ["error", "all"],

// No async function without await
"require-await": "error",

// Force dot notation when possible
"dot-notation": "error",

// Force object shorthand where possible
"object-shorthand": "error",

// No useless destructuring/importing/exporting renames
"no-useless-rename": "error"
}
}
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: corepack enable
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "pnpm"
- run: pnpm install
- run: pnpm lint
- run: pnpm test
- run: pnpm coverage && rm -rf coverage/tmp
- uses: codecov/codecov-action@v3
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ test/benchmarks/macro/fixtures/*
test/bundlers/**/bundle.js
test/bundlers/parcel-test/.parcel-cache

dist
dist
.eslintcache
coverage
.profile
.idea
34 changes: 31 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
"version": "1.0.0",
"description": "The official OpenSearch client for Node.js",
"type": "module",
"main": "index.js",
"main": "index.ts",
"exports": {
".": {
"import": "./dist/esm/index.js",
"require": "./dist/esm/index.js",
"default": "./dist/cjs/index.js"
}
},
"scripts": {
"test": "vitest",
"lint": "eslint --cache --ext .ts,.js,.mjs,.cjs . && prettier src",
"lint:fix": "eslint --cache --ext .ts,.js,.mjs,.cjs . --fix && prettier src -w",
"coverage": "vitest run --coverage",
"unbuild": "unbuild",
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build": ""
"build": "tsc --emitDeclarationOnly & tsc -p tsconfig.cjs.json & tsc -p tsconfig.esm.json",
"tsup": "npx tsup src/index.ts --format cjs,esm --dts "
},
"repository": {
"type": "git",
Expand All @@ -22,12 +34,28 @@
},
"homepage": "https://github.com/timursaurus/opensearch-ts#readme",
"devDependencies": {
"@types/aws4": "^1.11.2",
"@types/debug": "^4.1.7",
"@typescript-eslint/eslint-plugin": "^5.56.0",
"@typescript-eslint/parser": "^5.56.0",
"@vitest/coverage-c8": "^0.29.7",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-standard": "^17.0.0",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.1.1",
"prettier": "^2.8.7",
"typescript": "^5.0.2",
"unbuild": "^1.1.2",
"vitest": "^0.29.7"
},
"dependencies": {
"aws4": "^1.12.0",
"debug": "^4.3.4",
"querystring": "^0.2.1",
"hpagent": "^1.2.0",
"secure-json-parse": "^2.7.0"
}
}
41 changes: 19 additions & 22 deletions tests/unit/serializer.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { stringify } from "node:querystring";
import { test } from "vitest";
import { stringify } from "querystring";

import { DeserializationError, SerializationError } from "@/errors";
import { Serializer } from "@/transport";

Expand Down Expand Up @@ -52,7 +51,6 @@ test("qserialize (array)", (t) => {
hello: "world",
arr: ["foo", "bar"],
};

t.expect(s.qserialize(obj)).toBe("hello=world&arr=foo%2Cbar");
});

Expand All @@ -62,7 +60,6 @@ test("qserialize (string)", (t) => {
hello: "world",
you_know: "for search",
};

t.expect(s.qserialize(stringify(obj))).toBe(stringify(obj));
});

Expand All @@ -83,8 +80,8 @@ test("SerializationError", (t) => {
try {
s.serialize(obj);
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(SerializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(SerializationError);
}
});

Expand All @@ -94,8 +91,8 @@ test("SerializationError ndserialize", (t) => {
// @ts-expect-error
s.ndserialize({ hello: "world" });
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(SerializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(SerializationError);
}
});

Expand All @@ -105,8 +102,8 @@ test("DeserializationError", (t) => {
try {
s.deserialize(json);
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(DeserializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(DeserializationError);
}
});

Expand All @@ -115,14 +112,14 @@ test("prototype poisoning protection", (t) => {
try {
s.deserialize('{"__proto__":{"foo":"bar"}}');
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(DeserializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(DeserializationError);
}
try {
s.deserialize('{"constructor":{"prototype":{"foo":"bar"}}}');
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(DeserializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(DeserializationError);
}
});

Expand All @@ -131,14 +128,14 @@ test("disable prototype poisoning protection", (t) => {
try {
const result = s.deserialize('{"__proto__":{"foo":"bar"}}');
t.expect(result).toBeInstanceOf(Object);
} catch (err) {
} catch {
throw new Error("Should not fail");
}

try {
const result = s.deserialize('{"constructor":{"prototype":{"foo":"bar"}}}');
t.expect(result).toBeInstanceOf(Object);
} catch (err) {
} catch {
throw new Error("Should not fail");
}
});
Expand All @@ -148,15 +145,15 @@ test("disable prototype poisoning protection only for proto", (t) => {
try {
const result = s.deserialize('{"__proto__":{"foo":"bar"}}');
t.expect(result).toBeInstanceOf(Object);
} catch (err) {
} catch {
throw new Error("Should not fail");
}

try {
s.deserialize('{"constructor":{"prototype":{"foo":"bar"}}}');
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(DeserializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(DeserializationError);
}
});

Expand All @@ -167,14 +164,14 @@ test("disable prototype poisoning protection only for constructor", (t) => {
try {
s.deserialize('{"__proto__":{"foo":"bar"}}');
throw new Error("Should fail");
} catch (err) {
t.expect(err).toBeInstanceOf(DeserializationError);
} catch (error) {
t.expect(error).toBeInstanceOf(DeserializationError);
}

try {
const result = s.deserialize('{"constructor":{"prototype":{"foo":"bar"}}}');
t.expect(result).toBeInstanceOf(Object);
} catch (err) {
} catch {
throw new Error("Should not fail");
}
});
8 changes: 6 additions & 2 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { defineConfig } from "vitest/config";

export default defineConfig({
test: {},
test: {
coverage: {
provider: 'c8'
}
},
resolve: {
alias: {
"@": new URL("./src", import.meta.url).pathname,
"@": new URL("src", import.meta.url).pathname,
},
},
});
Loading

0 comments on commit ae92cb5

Please sign in to comment.