DefinitelyTyped/types/serverless/serverless-tests.ts
timtrinidad 20a5f8e6e2 [serverless] fix hooks and cloudformation.resources definitions (#38315)
* Update serverless types

This fixes a couple of inconsistencies with the type declarations:
* `Plugin.hooks` is a dictionary of functions that return a promise, not a dictionary of promises
* `serverless.service.provider.compiledCloudFormationTemplate.Resources` is an object rather than an array

* make Plugin an interface instead of an abstract class

* add provider.naming

* add plugin constructor typedef as PluginStatic
2019-10-01 09:31:31 -07:00

49 lines
1.2 KiB
TypeScript

import Serverless from 'serverless';
import Plugin from 'serverless/classes/Plugin';
import PluginManager from 'serverless/classes/PluginManager';
const options: Serverless.Options = {
noDeploy: false,
stage: null,
region: '',
};
const serverless = new Serverless();
class CustomPlugin implements Plugin {
commands = {
command: {
usage: 'description',
lifecycleEvents: ['start'],
options: {
option: {
usage: `description`,
required: true,
shortcut: 'o',
},
},
},
};
customProp = {};
hooks: Plugin.Hooks;
constructor(serverless: Serverless, options: Serverless.Options) {
this.hooks = {
'command:start': () => {},
};
}
}
// Test a plugin with missing 'hooks' property
class BadPlugin implements Plugin { // $ExpectError
hoooks: Plugin.Hooks; // emulate a bad 'hooks' definition with a typo
constructor(badArg: number) {}
}
const manager = new PluginManager(serverless);
manager.addPlugin(CustomPlugin);
// Test adding a plugin with an incorrect constructor
manager.addPlugin(BadPlugin); // $ExpectError