Skip to content

Commit 72840c0

Browse files
author
Alice
committed
swapped raw config func to promise with correct typing
1 parent 4649e55 commit 72840c0

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/__tests__/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ describe('index.js', () => {
8686
describe('#findState', () => {
8787
it('should throw err - serverless.yml not exists', () => {
8888
// stepFunctionsOfflinePlugin.serverless.config = process.cwd() + '/serverless.test.yml';
89-
expect(stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]).toThrowError(
90-
'Could not find serverless manifest'
89+
stepFunctionsOfflinePlugin.hooks[global['hooks'].findState]().catch(e =>
90+
expect(e.message).toEqual('Could not find serverless manifest')
9191
);
9292
});
9393

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
196196
});
197197
}
198198

199-
getRawConfig(): Promise<any> {
199+
async getRawConfig(): Promise<ServerlessWithError['service']> {
200200
const serverlessPath = this.serverless.config.servicePath;
201201
if (!serverlessPath) {
202202
throw new this.serverless.classes.Error('Could not find serverless manifest');
@@ -213,9 +213,15 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
213213
`Could not find serverless manifest at path ${serverlessPath}. If this path is incorreect you should adjust the 'servicePath' variable`
214214
);
215215
}
216-
216+
let fromFile: ServerlessWithError['service'];
217217
if (/\.json|\.js$/.test(manifestFilename)) {
218-
return import(manifestFilename);
218+
try {
219+
fromFile = await import(manifestFilename);
220+
return fromFile;
221+
} catch (err) {
222+
console.error(err);
223+
throw new Error(`Unable to import manifest at: ${manifestFilename}`);
224+
}
219225
}
220226

221227
return this.serverless.yamlParser.parse(manifestFilename);

0 commit comments

Comments
 (0)