forked from redwoodjs/redwood
-
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.
fix(sls): Package nested functions too (redwoodjs#5850)
- Loading branch information
Showing
6 changed files
with
123 additions
and
17 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
nodeFileTrace: jest.fn(), | ||
} |
70 changes: 70 additions & 0 deletions
70
packages/cli/src/commands/deploy/__tests__/nftPack.test.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,70 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import { buildApi, findApiDistFunctions } from '@redwoodjs/internal' | ||
|
||
import nftPacker from '../packing/nft' | ||
|
||
const FIXTURE_PATH = path.resolve( | ||
__dirname, | ||
'../../../../../../__fixtures__/example-todo-main' | ||
) | ||
|
||
let functionDistFiles | ||
|
||
beforeAll(() => { | ||
process.env.RWJS_CWD = FIXTURE_PATH | ||
|
||
// Actually build the fixture, if we need it | ||
if (!fs.existsSync(path.join(FIXTURE_PATH, 'api/dist/functions'))) { | ||
buildApi() | ||
} | ||
|
||
functionDistFiles = findApiDistFunctions() | ||
}) | ||
|
||
afterAll(() => { | ||
delete process.env.RWJS_CWD | ||
}) | ||
|
||
test('Check packager detects all functions', () => { | ||
const packageFileMock = jest | ||
.spyOn(nftPacker, 'packageSingleFunction') | ||
.mockResolvedValue(true) | ||
|
||
nftPacker.nftPack() | ||
|
||
expect(packageFileMock).toHaveBeenCalledTimes(5) | ||
}) | ||
|
||
test('Creates entry file for nested functions correctly', () => { | ||
const nestedFunction = functionDistFiles.find((fPath) => | ||
fPath.includes('nested') | ||
) | ||
|
||
const [outputPath, content] = nftPacker.generateEntryFile( | ||
nestedFunction, | ||
'nested' | ||
) | ||
|
||
expect(outputPath).toBe('./api/dist/zipball/nested/nested.js') | ||
expect(content).toMatchInlineSnapshot( | ||
`"module.exports = require('./api/dist/functions/nested/nested.js')"` | ||
) | ||
}) | ||
|
||
test('Creates entry file for top level functions correctly', () => { | ||
const graphqlFunction = functionDistFiles.find((fPath) => | ||
fPath.includes('graphql') | ||
) | ||
|
||
const [outputPath, content] = nftPacker.generateEntryFile( | ||
graphqlFunction, | ||
'graphql' | ||
) | ||
|
||
expect(outputPath).toBe('./api/dist/zipball/graphql/graphql.js') | ||
expect(content).toMatchInlineSnapshot( | ||
`"module.exports = require('./api/dist/functions/graphql.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
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