diff --git a/config/jest-client.config.js b/config/jest-client.config.js new file mode 100644 index 000000000..3bfbd195c --- /dev/null +++ b/config/jest-client.config.js @@ -0,0 +1,40 @@ +const path = require("path"); + +module.exports = { + displayName: "client", + rootDir: "../", + roots: ["/src/core/client"], + collectCoverageFrom: ["**/*.{js,jsx,mjs,ts,tsx}"], + coveragePathIgnorePatterns: ["/node_modules/"], + setupFiles: [ + "/config/polyfills.js", + "/src/core/client/test/setup.ts", + ], + testMatch: ["**/*.spec.{js,jsx,mjs,ts,tsx}"], + testEnvironment: "node", + testURL: "http://localhost", + transform: { + "^.+\\.tsx?$": "/node_modules/ts-jest", + "^.+\\.css$": "/config/jest/cssTransform.js", + "^(?!.*\\.(js|jsx|mjs|ts|tsx|css|json|ftl)$)": + "/config/jest/fileTransform.js", + }, + transformIgnorePatterns: [ + "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$", + ], + moduleNameMapper: { + "^talk-admin/(.*)$": "/src/core/client/admin/$1", + "^talk-ui/(.*)$": "/src/core/client/ui/$1", + "^talk-stream/(.*)$": "/src/core/client/stream/$1", + "^talk-framework/(.*)$": "/src/core/client/framework/$1", + "^talk-common/(.*)$": "/src/core/common/$1", + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], + snapshotSerializers: ["enzyme-to-json/serializer"], + globals: { + "ts-jest": { + useBabelrc: true, + tsConfigFile: path.resolve(__dirname, "tsconfig.jest.json"), + }, + }, +}; diff --git a/config/jest-server.config.js b/config/jest-server.config.js new file mode 100644 index 000000000..6ac9556bf --- /dev/null +++ b/config/jest-server.config.js @@ -0,0 +1,19 @@ +module.exports = { + displayName: "server", + rootDir: "../", + roots: ["/src"], + collectCoverageFrom: ["**/*.{js,jsx,mjs,ts,tsx}"], + coveragePathIgnorePatterns: ["/node_modules/"], + testMatch: ["**/*.spec.{js,jsx,mjs,ts,tsx}"], + testPathIgnorePatterns: ["/node_modules/", "/client/"], + testEnvironment: "node", + testURL: "http://localhost", + transform: { + "^.+\\.tsx?$": "/node_modules/ts-jest", + }, + moduleNameMapper: { + "^talk-server/(.*)$": "/src/core/server/$1", + "^talk-common/(.*)$": "/src/core/common/$1", + }, + moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], +}; diff --git a/config/jest.config.js b/config/jest.config.js index d2f436f94..3e7166a29 100644 --- a/config/jest.config.js +++ b/config/jest.config.js @@ -1,48 +1,6 @@ -const path = require("path"); -const paths = require("./paths"); - module.exports = { - rootDir: "../", - roots: ["/src", "/scripts"], - collectCoverageFrom: ["src/**/*.{js,jsx,mjs,ts,tsx}"], - coveragePathIgnorePatterns: ["/node_modules/"], - setupFiles: ["/config/polyfills.js", "/test/setupjest.ts"], - testMatch: ["**/*.spec.{js,jsx,mjs,ts,tsx}"], - testEnvironment: "node", - testURL: "http://localhost", - transform: { - "^.+\\.(js|jsx|mjs|ts|tsx)$": "/node_modules/ts-jest", - "^.+\\.css$": "/config/jest/cssTransform.js", - "^(?!.*\\.(js|jsx|mjs|css|json|ftl)$)": - "/config/jest/fileTransform.js", - }, - transformIgnorePatterns: [ - "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$", + projects: [ + "/jest-client.config.js", + "/jest-server.config.js", ], - moduleNameMapper: { - "^talk-admin/(.*)$": "/src/core/client/admin/$1", - "^talk-ui/(.*)$": "/src/core/client/ui/$1", - "^talk-stream/(.*)$": "/src/core/client/stream/$1", - "^talk-framework/(.*)$": "/src/core/client/framework/$1", - "^talk-common/(.*)$": "/src/core/common/$1", - "^talk-server/(.*)$": "/src/core/server/$1", - }, - moduleFileExtensions: [ - "web.js", - "js", - "json", - "web.jsx", - "jsx", - "node", - "mjs", - "ts", - "tsx", - ], - snapshotSerializers: ["enzyme-to-json/serializer"], - globals: { - "ts-jest": { - useBabelrc: true, - tsConfigFile: path.resolve(__dirname, "tsconfig.jest.json"), - }, - }, }; diff --git a/test/enzyme.ts b/src/core/client/test/enzyme.ts similarity index 100% rename from test/enzyme.ts rename to src/core/client/test/enzyme.ts diff --git a/test/jsdom.ts b/src/core/client/test/jsdom.ts similarity index 100% rename from test/jsdom.ts rename to src/core/client/test/jsdom.ts diff --git a/test/setupjest.ts b/src/core/client/test/setup.ts similarity index 100% rename from test/setupjest.ts rename to src/core/client/test/setup.ts diff --git a/src/core/server/models/connection.spec.ts b/src/core/server/models/connection.spec.ts new file mode 100644 index 000000000..cf4cf8af1 --- /dev/null +++ b/src/core/server/models/connection.spec.ts @@ -0,0 +1,59 @@ +import { getPageInfo } from "./connection"; + +it("handles when there is none requested", () => { + const pageInfo = getPageInfo({ first: 0 }, []); + + expect(pageInfo).toEqual({ + hasNextPage: false, + hasPreviousPage: false, + startCursor: null, + endCursor: null, + }); +}); + +it("handles when there is no edges", () => { + const pageInfo = getPageInfo({ first: 10 }, []); + + expect(pageInfo).toEqual({ + hasNextPage: false, + hasPreviousPage: false, + startCursor: null, + endCursor: null, + }); +}); + +it("handles when there is more edges than requested", () => { + const pageInfo = getPageInfo({ first: 1 }, [ + { + node: null, + cursor: 1, + }, + { + node: null, + cursor: 2, + }, + ]); + + expect(pageInfo).toEqual({ + hasNextPage: true, + hasPreviousPage: false, + startCursor: null, + endCursor: 1, + }); +}); + +it("handles when there is exactly as many edges as requested", () => { + const pageInfo = getPageInfo({ first: 1 }, [ + { + node: null, + cursor: 1, + }, + ]); + + expect(pageInfo).toEqual({ + hasNextPage: false, + hasPreviousPage: false, + startCursor: null, + endCursor: 1, + }); +}); diff --git a/test/.babelrc.js b/test/.babelrc.js deleted file mode 100644 index 260a43f69..000000000 --- a/test/.babelrc.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - presets: [ - ["@babel/env", { targets: "last 2 versions, ie 11", modules: "commonjs" }], - "@babel/react", - ], -};