forked from serverless-nextjs/serverless-next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda-at-edge): add serverless trace target support (serverless…
- Loading branch information
1 parent
fa4d3e3
commit eac52de
Showing
21 changed files
with
760 additions
and
46 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
!tests/fixtures/** | ||
!tests/serverless-trace/** | ||
dist/ |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
packages/lambda-at-edge/tests/serverless-trace/.next/prerender-manifest.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 @@ | ||
{} |
8 changes: 8 additions & 0 deletions
8
packages/lambda-at-edge/tests/serverless-trace/.next/serverless/pages-manifest.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,8 @@ | ||
{ | ||
"/api/test-page": "pages/api/test-api-page.js", | ||
"/api/sub/[dynamic-test-api-page]": "pages/api/sub/[dynamic-test-api-page].js", | ||
"/test-page": "pages/test-page.js", | ||
"/sub/[dynamic-test-page]": "pages/sub/[dynamic-test-page].js", | ||
"/_app": "pages/_app.js", | ||
"/_document": "pages/_document.js" | ||
} |
Empty file.
3 changes: 3 additions & 0 deletions
3
...-at-edge/tests/serverless-trace/.next/serverless/pages/api/sub/[dynamic-test-api-page].js
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 @@ | ||
const apiDependencyB = require("api-dependency-b"); | ||
|
||
module.exports = {}; |
3 changes: 3 additions & 0 deletions
3
packages/lambda-at-edge/tests/serverless-trace/.next/serverless/pages/api/test-api-page.js
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 @@ | ||
const apiDependency = require("api-dependency-a"); | ||
|
||
module.exports = {}; |
6 changes: 6 additions & 0 deletions
6
...s/lambda-at-edge/tests/serverless-trace/.next/serverless/pages/sub/[dynamic-test-page].js
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,6 @@ | ||
// the following dependency is shared with other pages but should be copied over to artefact only once | ||
const someDependency = require("dependency-a"); | ||
|
||
const anotherDependency = require("dependency-b"); | ||
|
||
module.exports = {}; |
3 changes: 3 additions & 0 deletions
3
packages/lambda-at-edge/tests/serverless-trace/.next/serverless/pages/test-page.js
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 @@ | ||
const someDependency = require("dependency-a"); | ||
|
||
module.exports = {}; |
3 changes: 3 additions & 0 deletions
3
packages/lambda-at-edge/tests/serverless-trace/next.config.js
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 @@ | ||
module.exports = { | ||
target: "experimental-serverless-trace" | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/lambda-at-edge/tests/serverless-trace/node_modules/api-dependency-a/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/lambda-at-edge/tests/serverless-trace/node_modules/api-dependency-b/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
packages/lambda-at-edge/tests/serverless-trace/node_modules/dependency-a/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/lambda-at-edge/tests/serverless-trace/node_modules/dependency-a/sub-dependency.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/lambda-at-edge/tests/serverless-trace/node_modules/dependency-b/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
packages/lambda-at-edge/tests/serverless-trace/test/serverless-trace.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,91 @@ | ||
import fse from "fs-extra"; | ||
import os from "os"; | ||
import path from "path"; | ||
import Builder from "../../../src/build"; | ||
import { | ||
DEFAULT_LAMBDA_CODE_DIR, | ||
API_LAMBDA_CODE_DIR | ||
} from "../../../src/build"; | ||
|
||
describe("Serverless Trace", () => { | ||
const fixturePath = path.join(__dirname, "../"); | ||
let outputDir: string; | ||
let fseRemoveSpy: jest.SpyInstance; | ||
|
||
beforeEach(async () => { | ||
outputDir = os.tmpdir(); | ||
|
||
fseRemoveSpy = jest.spyOn(fse, "remove").mockImplementation(() => { | ||
return; | ||
}); | ||
|
||
const builder = new Builder(fixturePath, outputDir); | ||
|
||
await builder.build(); | ||
}); | ||
|
||
afterEach(() => { | ||
fseRemoveSpy.mockRestore(); | ||
}); | ||
|
||
it("copies api page dependencies to api lambda artefact", async () => { | ||
const nodeModulesPath = path.join( | ||
outputDir, | ||
API_LAMBDA_CODE_DIR, | ||
"node_modules" | ||
); | ||
|
||
const nodeModulesExists = await fse.pathExists(nodeModulesPath); | ||
expect(nodeModulesExists).toBe(true); | ||
|
||
const nodeModulesFiles = await fse.readdir(nodeModulesPath); | ||
expect(nodeModulesFiles).toEqual( | ||
expect.arrayContaining(["api-dependency-a", "api-dependency-b"]) | ||
); | ||
|
||
const dependencyAPath = path.join(nodeModulesPath, "api-dependency-a"); | ||
const dependencyAFiles = await fse.readdir(dependencyAPath); | ||
expect(dependencyAFiles).toEqual(expect.arrayContaining(["index.js"])); | ||
|
||
const dependencyBPath = path.join(nodeModulesPath, "api-dependency-b"); | ||
const dependencyBFiles = await fse.readdir(dependencyBPath); | ||
expect(dependencyBFiles).toEqual(expect.arrayContaining(["index.js"])); | ||
}); | ||
|
||
it("copies ssr page dependencies to lambda artefact", async () => { | ||
const nodeModulesPath = path.join( | ||
outputDir, | ||
DEFAULT_LAMBDA_CODE_DIR, | ||
"node_modules" | ||
); | ||
|
||
const nodeModulesExists = await fse.pathExists(nodeModulesPath); | ||
expect(nodeModulesExists).toBe(true); | ||
|
||
const nodeModulesFiles = await fse.readdir(nodeModulesPath); | ||
expect(nodeModulesFiles).toEqual( | ||
expect.arrayContaining(["dependency-a", "dependency-b"]) | ||
); | ||
|
||
const dependencyAPath = path.join(nodeModulesPath, "dependency-a"); | ||
const dependencyAFiles = await fse.readdir(dependencyAPath); | ||
expect(dependencyAFiles).toEqual( | ||
expect.arrayContaining(["index.js", "sub-dependency.js"]) | ||
); | ||
|
||
const dependencyBPath = path.join(nodeModulesPath, "dependency-b"); | ||
const dependencyBFiles = await fse.readdir(dependencyBPath); | ||
expect(dependencyBFiles).toEqual(expect.arrayContaining(["index.js"])); | ||
}); | ||
|
||
it("does not copy any .next/ files into lambda artefact", async () => { | ||
const nodeModulesPath = path.join( | ||
outputDir, | ||
DEFAULT_LAMBDA_CODE_DIR, | ||
".next" | ||
); | ||
|
||
const dotNextDirExists = await fse.pathExists(nodeModulesPath); | ||
expect(dotNextDirExists).toBe(false); | ||
}); | ||
}); |
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
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
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