-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct local invoke for non node functions
- Loading branch information
1 parent
7c9c8f5
commit 2bfb9d0
Showing
2 changed files
with
44 additions
and
2 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,7 +1,10 @@ | ||
import { EsbuildServerlessPlugin } from '.'; | ||
|
||
export function preLocal(this: EsbuildServerlessPlugin) { | ||
this.serviceDirPath = this.buildDirPath; | ||
this.serverless.config.servicePath = this.buildDirPath; | ||
// Set service path as CWD to allow accessing bundled files correctly | ||
process.chdir(this.serviceDirPath); | ||
// If this is a node function set the service path as CWD to allow accessing bundled files correctly | ||
if (this.functions[this.options.function]) { | ||
process.chdir(this.serviceDirPath); | ||
} | ||
} |
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,39 @@ | ||
import { preLocal } from '../pre-local'; | ||
|
||
const chdirSpy = jest.spyOn(process, 'chdir').mockImplementation(); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('should call chdir with the buildDirPath if the invoked function is a node function', () => { | ||
const esbuildPlugin = { | ||
buildDirPath: 'workdir/.build', | ||
serverless: { | ||
config: {}, | ||
}, | ||
options: { | ||
function: 'hello', | ||
}, | ||
functions: { | ||
hello: {}, | ||
}, | ||
}; | ||
preLocal.call(esbuildPlugin); | ||
expect(chdirSpy).toBeCalledWith(esbuildPlugin.buildDirPath); | ||
}); | ||
|
||
it('should not call chdir if the invoked function is not a node function', () => { | ||
const esbuildPlugin = { | ||
buildDirPath: 'workdir/.build', | ||
serverless: { | ||
config: {}, | ||
}, | ||
options: { | ||
function: 'hello', | ||
}, | ||
functions: {}, | ||
}; | ||
preLocal.call(esbuildPlugin); | ||
expect(chdirSpy).not.toBeCalled(); | ||
}); |