-
-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lambda-at-edge): for serverless-trace target, exclude files that …
…are not in node-modules folder (#758)
- Loading branch information
Showing
9 changed files
with
138 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...edge/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.next |
3 changes: 3 additions & 0 deletions
3
.../integration/serverless-trace-with-dynamic-import-typescript/fixture/components/hello.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as React from "react"; | ||
|
||
export default () => <span>Hello World</span>; |
2 changes: 2 additions & 0 deletions
2
...e/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/next-env.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// <reference types="next" /> | ||
/// <reference types="next/types/global" /> |
5 changes: 5 additions & 0 deletions
5
...ts/integration/serverless-trace-with-dynamic-import-typescript/fixture/pages/api/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default (req: any, res: any) => { | ||
res.statusCode = 200; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.end(JSON.stringify({ name: "John Doe" })); | ||
}; |
15 changes: 15 additions & 0 deletions
15
...tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/pages/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import dynamic from "next/dynamic"; | ||
import * as React from "react"; | ||
|
||
const DynamicComponent = dynamic(() => import("../components/hello")); | ||
|
||
const Page = () => <DynamicComponent />; | ||
|
||
Page.getInitialProps = () => { | ||
// just forcing this page to be server side rendered | ||
return { | ||
foo: "bar" | ||
}; | ||
}; | ||
|
||
export default Page; |
29 changes: 29 additions & 0 deletions
29
...e/tests/integration/serverless-trace-with-dynamic-import-typescript/fixture/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": [ | ||
"dom", | ||
"dom.iterable", | ||
"esnext" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve" | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"**/*.ts", | ||
"**/*.tsx" | ||
], | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
75 changes: 75 additions & 0 deletions
75
...ce-with-dynamic-import-typescript/serverless-trace-with-dynamic-import-typescript.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { remove, readdir, pathExists } from "fs-extra"; | ||
import path from "path"; | ||
import os from "os"; | ||
import Builder from "../../../src/build"; | ||
import { getNextBinary } from "../../test-utils"; | ||
import klaw from "klaw"; | ||
|
||
jest.unmock("execa"); | ||
|
||
describe("Serverless Trace With Dynamic Import - TypeScript", () => { | ||
const nextBinary = getNextBinary(); | ||
const fixtureDir = path.join(__dirname, "./fixture"); | ||
let outputDir: string; | ||
|
||
beforeAll(async () => { | ||
outputDir = path.join(os.tmpdir(), "slsnext-test-build"); | ||
const builder = new Builder(fixtureDir, outputDir, { | ||
cwd: fixtureDir, | ||
cmd: nextBinary, | ||
args: ["build"], | ||
useServerlessTraceTarget: true | ||
}); | ||
|
||
await builder.build(); | ||
}); | ||
|
||
afterAll(() => { | ||
return Promise.all( | ||
[".next"].map((file) => remove(path.join(fixtureDir, file))) | ||
); | ||
}); | ||
|
||
it("copies node_modules to default lambda artefact", async () => { | ||
const nodeModules = await readdir( | ||
path.join(outputDir, "default-lambda/node_modules") | ||
); | ||
expect(nodeModules.length).toBeGreaterThan(5); // 5 is just an arbitrary number to ensure dependencies are being copied | ||
}); | ||
|
||
it("copies node_modules to api lambda artefact", async () => { | ||
const nodeModules = await readdir( | ||
path.join(outputDir, "api-lambda/node_modules") | ||
); | ||
expect(nodeModules).toEqual(["next"]); | ||
}); | ||
|
||
it("copies dynamic chunk to default lambda artefact", async () => { | ||
const chunkFileName = ( | ||
await readdir(path.join(fixtureDir, ".next/serverless")) | ||
).find((file) => { | ||
return /^[\d]+\.+[\w,\s-]+\.(js)$/.test(file); | ||
}); | ||
|
||
expect(chunkFileName).toBeDefined(); | ||
|
||
const chunkExistsInOutputBuild = await pathExists( | ||
path.join(outputDir, "default-lambda", chunkFileName as string) | ||
); | ||
|
||
expect(chunkExistsInOutputBuild).toBe(true); | ||
}); | ||
|
||
it("does not copy TypeScript sources", async () => { | ||
const defaultLambdaFiles: string[] = []; | ||
klaw(path.join(outputDir, "default-lambda")).on("data", (item) => | ||
defaultLambdaFiles.push(item.path) | ||
); | ||
|
||
const typeScriptFileName = defaultLambdaFiles.find((file) => { | ||
return /^[\d]+\.+[\w,\s-]+\.(ts|tsx)$/.test(file); | ||
}); | ||
|
||
expect(typeScriptFileName).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Woops, commit message is wrong, not sure how that happened. Should be "exclude files that are TypeScript sources"