From f2da9239777c9a28990ad407da5ab77c041a2838 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Fri, 14 Aug 2020 15:45:53 +0300 Subject: [PATCH] switch to eslint move tests to src/, because otherwise import plugin doesn't work --- .eslintrc.js | 26 +++++- frontend/.eslintrc.js | 6 ++ package-lock.json | 93 +++++++++++++++++++ package.json | 5 +- src/tests/integration/.eslintrc.js | 4 + {tests => src/tests}/integration/docs.test.ts | 22 ++--- .../tests}/integration/users.test.ts | 20 ++-- {tests => src/tests}/integration/util.ts | 0 8 files changed, 153 insertions(+), 23 deletions(-) create mode 100644 frontend/.eslintrc.js create mode 100644 src/tests/integration/.eslintrc.js rename {tests => src/tests}/integration/docs.test.ts (88%) rename {tests => src/tests}/integration/users.test.ts (89%) rename {tests => src/tests}/integration/util.ts (100%) diff --git a/.eslintrc.js b/.eslintrc.js index 979a83c..b286515 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,14 +1,38 @@ module.exports = { root: true, parser: "@typescript-eslint/parser", - plugins: ["@typescript-eslint"], + plugins: ["@typescript-eslint", "prettier"], extends: [ "eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier/@typescript-eslint", + "plugin:react-hooks/recommended", + "plugin:react/recommended", + "plugin:import/errors", + "plugin:import/warnings", + "plugin:import/typescript" ], env: { browser: true, node: true }, + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "settings": { + "import/parsers": { + "@typescript-eslint/parser": [".ts", ".tsx"] + }, + "import/resolver": { + "typescript": { + "alwaysTryTypes": true, + "project": [ + "./tsconfig.json", + "./frontend/tsconfig.json" + ] + }, + } + } + }; diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js new file mode 100644 index 0000000..0a95d09 --- /dev/null +++ b/frontend/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: ["jest"], + extends: [ + 'plugin:jest/recommended', + ], +}; diff --git a/package-lock.json b/package-lock.json index 7bd9eb2..2ddb72b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1749,6 +1749,30 @@ } } }, + "eslint-import-resolver-typescript": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-2.2.0.tgz", + "integrity": "sha512-/NhKEH1gbRlcb9RcaZJe5zRn5eIffGTf1qh3JAyvkEuPli3DEa5HQWWUO5OTfUjj7buUXsDq8lEsdwbbSeqywg==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "resolve": "^1.17.0", + "tsconfig-paths": "^3.9.0" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + } + } + }, "eslint-module-utils": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.6.0.tgz", @@ -1824,6 +1848,59 @@ } } }, + "eslint-plugin-jest": { + "version": "23.20.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.20.0.tgz", + "integrity": "sha512-+6BGQt85OREevBDWCvhqj1yYA4+BFK4XnRZSGJionuEYmcglMZYLNNBBemwzbqUAckURaHdJSBcjHPyrtypZOw==", + "dev": true, + "requires": { + "@typescript-eslint/experimental-utils": "^2.5.0" + }, + "dependencies": { + "@typescript-eslint/experimental-utils": { + "version": "2.34.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz", + "integrity": "sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==", + "dev": true, + "requires": { + "@types/json-schema": "^7.0.3", + "@typescript-eslint/typescript-estree": "2.34.0", + "eslint-scope": "^5.0.0", + "eslint-utils": "^2.0.0" + } + }, + "@typescript-eslint/typescript-estree": { + "version": "2.34.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz", + "integrity": "sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==", + "dev": true, + "requires": { + "debug": "^4.1.1", + "eslint-visitor-keys": "^1.1.0", + "glob": "^7.1.6", + "is-glob": "^4.0.1", + "lodash": "^4.17.15", + "semver": "^7.3.2", + "tsutils": "^3.17.1" + } + }, + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "semver": { + "version": "7.3.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.2.tgz", + "integrity": "sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==", + "dev": true + } + } + }, "eslint-plugin-jsx-a11y": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.3.1.tgz", @@ -1851,6 +1928,16 @@ } } }, + "eslint-plugin-mocha": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-8.0.0.tgz", + "integrity": "sha512-n67etbWDz6NQM+HnTwZHyBwz/bLlYPOxUbw7bPuCyFujv7ZpaT/Vn6KTAbT02gf7nRljtYIjWcTxK/n8a57rQQ==", + "dev": true, + "requires": { + "eslint-utils": "^2.1.0", + "ramda": "^0.27.1" + } + }, "eslint-plugin-prettier": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz", @@ -3893,6 +3980,12 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.4.tgz", "integrity": "sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==" }, + "ramda": { + "version": "0.27.1", + "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz", + "integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw==", + "dev": true + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", diff --git a/package.json b/package.json index 6b9c1e3..ea701f0 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,11 @@ "eslint": "^7.6.0", "eslint-config-airbnb": "^18.2.0", "eslint-config-prettier": "^6.11.0", + "eslint-import-resolver-typescript": "^2.2.0", "eslint-plugin-import": "^2.22.0", + "eslint-plugin-jest": "^23.20.0", "eslint-plugin-jsx-a11y": "^6.3.1", + "eslint-plugin-mocha": "^8.0.0", "eslint-plugin-prettier": "^3.1.4", "eslint-plugin-react": "^7.20.6", "eslint-plugin-react-hooks": "^4.0.8", @@ -72,7 +75,7 @@ "build": "npm run build-backend && npm run build-frontend", "frontend": "cd frontend && npm start", "dev": "cross-env NODE_ENV=development concurrently npm:ts-node-dev npm:frontend -c 'blue,green'", - "test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register 'tests/**/*.ts' ", + "test": "cross-env NODE_ENV=test mocha --timeout 15000 -r ts-node/register -r tsconfig-paths/register 'src/tests/**/*.ts' ", "lint": "eslint ./src/** ./frontend/src/** --ext .js,.jsx,.ts,.tsx" }, "husky": { diff --git a/src/tests/integration/.eslintrc.js b/src/tests/integration/.eslintrc.js new file mode 100644 index 0000000..7c71e77 --- /dev/null +++ b/src/tests/integration/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + plugins: ["mocha"], + extends: ["plugin:mocha/recommended"], +}; diff --git a/tests/integration/docs.test.ts b/src/tests/integration/docs.test.ts similarity index 88% rename from tests/integration/docs.test.ts rename to src/tests/integration/docs.test.ts index 4edecbb..511c081 100644 --- a/tests/integration/docs.test.ts +++ b/src/tests/integration/docs.test.ts @@ -11,20 +11,20 @@ const callback = app.callback(); let seed: ISeed; -describe("docs", () => { - before(async () => { +describe("docs", function () { + before(async function () { await connect(); }); - after(async () => { + after(async function () { await getConnection().close(); }); - beforeEach(async () => { + beforeEach(async function () { seed = await seedDB(); }); - it("should create a document", async () => { + it("should create a document", async function () { const response = await request(callback) .post("/docs/new") .set({ @@ -48,7 +48,7 @@ describe("docs", () => { expect(dbDocument.name).to.be.equal("Test1"); }); - it("should update a document", async () => { + it("should update a document", async function () { const response = await request(callback) .patch(`/docs/byID/${seed.doc1.id}`) .set({ @@ -76,7 +76,7 @@ describe("docs", () => { ); }); - it("should list docs", async () => { + it("should list docs", async function () { const response = await request(callback) .get("/docs/list") .set({ @@ -96,7 +96,7 @@ describe("docs", () => { expect(documents).to.deep.equal(userDocs); }); - it("should get a shared document", async () => { + it("should get a shared document", async function () { const response = await request(callback) .get(`/docs/shared/${seed.user1.username}/${seed.doc2p.id}`) .expect(200); @@ -110,7 +110,7 @@ describe("docs", () => { expect(document).to.deep.equal(usedDoc); }); - it("should get a document", async () => { + it("should get a document", async function () { const response = await request(callback) .get(`/docs/byID/${seed.doc1.id}`) .set({ @@ -127,7 +127,7 @@ describe("docs", () => { expect(document).to.deep.equal(usedDoc); }); - it("should not get a document without jwt", async () => { + it("should not get a document without jwt", async function () { const response = await request(callback) .get(`/docs/byID/${seed.doc1.id}`) .set({ @@ -138,7 +138,7 @@ describe("docs", () => { expect(response.body.error).to.be.equal("Not Found"); }); - it("should delete a document", async () => { + it("should delete a document", async function () { const response = await request(callback) .delete(`/docs/byID/${seed.doc1.id}`) .set({ diff --git a/tests/integration/users.test.ts b/src/tests/integration/users.test.ts similarity index 89% rename from tests/integration/users.test.ts rename to src/tests/integration/users.test.ts index 97b8c0b..45a0914 100644 --- a/tests/integration/users.test.ts +++ b/src/tests/integration/users.test.ts @@ -11,20 +11,20 @@ const callback = app.callback(); let seed: ISeed; -describe("users", () => { - before(async () => { +describe("users", function () { + before(async function () { await connect(); }); - after(async () => { + after(async function () { await getConnection().close(); }); - beforeEach(async () => { + beforeEach(async function () { seed = await seedDB(); }); - it("should get user", async () => { + it("should get user", async function () { const response = await request(callback) .get("/users/user") .set({ @@ -41,7 +41,7 @@ describe("users", () => { expect(user).to.deep.equal(seed.user1.toJSON()); }); - it("should login user", async () => { + it("should login user", async function () { const response = await request(callback) .post("/users/login") .set({ "Content-Type": "application/json" }) @@ -56,7 +56,7 @@ describe("users", () => { expect(user).to.deep.equal(seed.user1.toJSON()); }); - it("should not login user with wrong password", async () => { + it("should not login user with wrong password", async function () { const response = await request(callback) .post("/users/login") .set({ "Content-Type": "application/json" }) @@ -67,7 +67,7 @@ describe("users", () => { expect(response.body.data).to.be.false; }); - it("should signup user", async () => { + it("should signup user", async function () { const response = await request(callback) .post("/users/signup") .set({ "Content-Type": "application/json" }) @@ -88,7 +88,7 @@ describe("users", () => { expect(user).to.deep.equal(newUser.toJSON()); }); - it("should not signup user with duplicate username", async () => { + it("should not signup user with duplicate username", async function () { const response = await request(callback) .post("/users/signup") .set({ "Content-Type": "application/json" }) @@ -103,7 +103,7 @@ describe("users", () => { expect(response.body.data).to.be.false; }); - it("should change user's password", async () => { + it("should change user's password", async function () { const response = await request(callback) .post("/users/edit") .set({ diff --git a/tests/integration/util.ts b/src/tests/integration/util.ts similarity index 100% rename from tests/integration/util.ts rename to src/tests/integration/util.ts