From 68a70f194fc85e591b396442ea8429a91e683486 Mon Sep 17 00:00:00 2001 From: eric-burel Date: Thu, 9 Jun 2022 18:10:37 +0200 Subject: [PATCH] swc first try --- .../nextConfig/{extendEnv.ts => extendEnv.js} | 2 +- ...est.js => babel.config.jest.js.deprecated} | 0 starters/next/jest.config.js | 21 +++++-- starters/next/src/types/md.d.ts | 4 ++ starters/next/src/types/mdx.d.ts | 4 -- .../models/tests/sampleModel.server.test.ts | 60 ------------------- 6 files changed, 22 insertions(+), 69 deletions(-) rename starters/next/.vn/nextConfig/{extendEnv.ts => extendEnv.js} (97%) rename starters/next/{babel.config.jest.js => babel.config.jest.js.deprecated} (100%) create mode 100644 starters/next/src/types/md.d.ts delete mode 100644 starters/next/src/vulcan-demo/models/tests/sampleModel.server.test.ts diff --git a/starters/next/.vn/nextConfig/extendEnv.ts b/starters/next/.vn/nextConfig/extendEnv.js similarity index 97% rename from starters/next/.vn/nextConfig/extendEnv.ts rename to starters/next/.vn/nextConfig/extendEnv.js index c4f977a8..210ed83c 100644 --- a/starters/next/.vn/nextConfig/extendEnv.ts +++ b/starters/next/.vn/nextConfig/extendEnv.js @@ -4,7 +4,7 @@ const debug = require("debug")("vns:next"); const packageJSON = require("../../package.json"); // fooBar => FOO_BAR -const camelToTitle = (camelStr: string): string => { +const camelToTitle = (camelStr /*: string*/) /*: string*/ => { return camelStr .replace(/[A-Z]/g, " $1") // fooBar => foo Bar .split(" ") diff --git a/starters/next/babel.config.jest.js b/starters/next/babel.config.jest.js.deprecated similarity index 100% rename from starters/next/babel.config.jest.js rename to starters/next/babel.config.jest.js.deprecated diff --git a/starters/next/jest.config.js b/starters/next/jest.config.js index 6bc199e5..9983817d 100644 --- a/starters/next/jest.config.js +++ b/starters/next/jest.config.js @@ -1,16 +1,26 @@ -// No need to use ts-jest https://github.com/vercel/next.js/discussions/13528#discussioncomment-22933 +const nextJest = require("next/jest"); -// configuration that must be set for each project but does not change +const createJestConfig = nextJest({ + // Provide the path to your Next.js app to load next.config.js and .env files in your test environment + dir: "./", +}); + +/** + * Configuration that must be set for each project (server and client) but does not change + * + */ const commonConfig = { // A map from regular expressions to paths to transformers // transform: undefined, transform: { + // Now we use SWC //"^.+\\.[jt]sx?$": "ts-jest", + /* "^.+\\.(js|jsx|ts|tsx|mjs)$": [ "babel-jest", , { configFile: "./Configuration/babel.config.jest.js" }, - ], + ],*/ // MDX support "^.+\\.(md|mdx)$": "jest-transformer-mdx", }, @@ -209,7 +219,7 @@ const commonConfig = { // watchman: true, }; -module.exports = { +const fullConfig = { // An array of glob patterns indicating a set of files for which coverage information should be collected collectCoverageFrom: [ "src/**/*.{js,jsx,ts,tsx}", @@ -267,3 +277,6 @@ module.exports = { }, ], }; + +// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async +module.exports = createJestConfig(fullConfig); diff --git a/starters/next/src/types/md.d.ts b/starters/next/src/types/md.d.ts new file mode 100644 index 00000000..a27bc214 --- /dev/null +++ b/starters/next/src/types/md.d.ts @@ -0,0 +1,4 @@ +declare module "*.md" { + let MDXComponent: (props: any) => JSX.Element; + export default MDXComponent; +} diff --git a/starters/next/src/types/mdx.d.ts b/starters/next/src/types/mdx.d.ts index e9eceda0..6ba8f3f9 100644 --- a/starters/next/src/types/mdx.d.ts +++ b/starters/next/src/types/mdx.d.ts @@ -3,7 +3,3 @@ declare module "*.mdx" { let MDXComponent: (props: any) => JSX.Element; export default MDXComponent; } -declare module "*.md" { - let MDXComponent: (props: any) => JSX.Element; - export default MDXComponent; -} diff --git a/starters/next/src/vulcan-demo/models/tests/sampleModel.server.test.ts b/starters/next/src/vulcan-demo/models/tests/sampleModel.server.test.ts deleted file mode 100644 index 973ea1af..00000000 --- a/starters/next/src/vulcan-demo/models/tests/sampleModel.server.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -// TODO: Unskip when updating to jest 28 -import { VulcanGraphqlModel } from "@vulcanjs/graphql"; -import { buildApolloSchema } from "@vulcanjs/graphql/server"; -import { ApolloServer } from "apollo-server-express"; -import { makeExecutableSchema } from "@graphql-tools/schema"; -import gql from "graphql-tag"; -// Import the server version in order to generate the graphql schema - -/** - * Create an Apollo Server for integration testing of graphql resolvers - * - * NOTE: this won't run an actual server on localhost:3000/graphql, - * it simply returns an Apollo server object - * - * Use executeOperation method to test queries - * - * @see https://www.apollographql.com/docs/apollo-server/testing/testing/ - */ -const createTestApolloServer = async ( - models: Array, - context: any -) => { - // Build a Vulcan schema just for this model - const vulcanRawSchema = buildApolloSchema(models); - const vulcanExecutableSchema = makeExecutableSchema(vulcanRawSchema); - // Spawn an Apollo server with just this schema - const server = new ApolloServer({ - schema: vulcanExecutableSchema, - debug: true, - context: {}, - }); - await server.start(); - return server; -}; -import { SampleModel } from "../sampleModel.server"; - -// TODO: this test doesn't pass, due to import issues, -// @see https://stackoverflow.com/questions/70420923/jest-modulenamemapper-and-npm-package-exports -// Until we fix this, you should test your server using Cypress "cy.request", as we demonstrate here: -// @see .vn/tests/vn/api/auth.server.test.ts -test.skip("can resolve a nested field", async () => { - const server = await createTestApolloServer([SampleModel], {}); - const result = server.executeOperation({ - // You can use GraphQL Playground to build the query and paste it there, - // by accessing http://localhost:3000/api/graphql in your browser during dev - query: gql` - { - samples { - results { - demoResolvedField( - someArgument: "someArgumentValue" - anotherArgument: 42 - ) - } - } - } - `, - }); - expect(result).toEqual([{ demoResolvedField: "todo" }]); -});