Skip to content

Commit 839c2ec

Browse files
author
Alice
committed
fixed cli for sls 3
1 parent ec81a7a commit 839c2ec

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

src/__tests__/build.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* istanbul ignore file */
22
import setup from './setup';
3+
import logging from './logging';
34

45
const { stepFunctionsOfflinePlugin, StepFunctionsOfflinePlugin, serverless } = setup();
56

src/__tests__/index.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging from './logging';
12
import setup from './setup';
23

34
const { stepFunctionsOfflinePlugin, StepFunctionsOfflinePlugin, serverless } = setup();
@@ -65,13 +66,13 @@ describe('index.js', () => {
6566
});
6667

6768
it('should apply event file ', async () => {
68-
const SFOP = new StepFunctionsOfflinePlugin(serverless, { e: 'src/__tests__/eventFile.json' });
69+
const SFOP = new StepFunctionsOfflinePlugin(serverless, { e: 'src/__tests__/eventFile.json' }, logging);
6970
await SFOP.hooks[global['hooks'].loadEventFile]();
7071
expect(SFOP.loadedEventFile).toMatchObject({ foo: 1, bar: 2 });
7172
});
7273

7374
it('should throw error - incorrect path to event file ', () => {
74-
const SFOP = new StepFunctionsOfflinePlugin(serverless, { event: '../__tests__/eventFile2.json' });
75+
const SFOP = new StepFunctionsOfflinePlugin(serverless, { event: '../__tests__/eventFile2.json' }, logging);
7576
expect(SFOP.hooks[global['hooks'].loadEventFile]).rejects.toEqual(
7677
expect.objectContaining({ code: 'MODULE_NOT_FOUND' })
7778
);
@@ -94,7 +95,7 @@ describe('index.js', () => {
9495
});
9596

9697
it('should throw error - incorrect path to event file ', () => {
97-
const SFOP = new StepFunctionsOfflinePlugin(serverless, { event: '..__tests__/eventFile.json' });
98+
const SFOP = new StepFunctionsOfflinePlugin(serverless, { event: '..__tests__/eventFile.json' }, logging);
9899
expect(SFOP.hooks[global['hooks'].loadEventFile]).rejects.toEqual(
99100
expect.objectContaining({ code: 'MODULE_NOT_FOUND' })
100101
);

src/__tests__/logging.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Logging } from 'serverless/classes/Plugin';
2+
3+
export default {
4+
log: {
5+
error: console.error,
6+
warning: console.warn,
7+
notice: console.info,
8+
verbose: console.info,
9+
success: console.info,
10+
info: console.info,
11+
debug: console.debug,
12+
},
13+
14+
writeText: console.log,
15+
progress: {
16+
get: () => {
17+
// empty function
18+
},
19+
create: () => {
20+
// empty function
21+
},
22+
} as unknown as Logging['progress'],
23+
} as Logging;

src/__tests__/setup.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* istanbul ignore file */
22
import Serverless from 'serverless';
3-
import CLI from 'serverless/lib/classes/CLI';
43
import { ServerlessWithError } from '../types';
54
import StepFunctionsOfflinePlugin from '..';
5+
import Logging from './logging';
66

77
export default function setup(): {
88
stepFunctionsOfflinePlugin: StepFunctionsOfflinePlugin;
@@ -13,7 +13,6 @@ export default function setup(): {
1313
commands: [],
1414
options: {},
1515
});
16-
serverless.cli = new CLI();
1716
// serverless.setProvider('aws', new AwsProvider(serverless));
1817
serverless.service.functions = {
1918
firstLambda: {
@@ -32,6 +31,10 @@ export default function setup(): {
3231
return {
3332
serverless: serverless as ServerlessWithError,
3433
StepFunctionsOfflinePlugin,
35-
stepFunctionsOfflinePlugin: new StepFunctionsOfflinePlugin(serverless as ServerlessWithError, global['options']),
34+
stepFunctionsOfflinePlugin: new StepFunctionsOfflinePlugin(
35+
serverless as ServerlessWithError,
36+
global['options'],
37+
Logging
38+
),
3639
};
3740
}

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import _ from 'lodash';
22
import path from 'path';
33
import moment from 'moment';
4-
import Plugin from 'serverless/classes/Plugin';
4+
import Plugin, { Logging } from 'serverless/classes/Plugin';
55

66
import { StateMachine, State, Map, Fail, Succeed, Task, Parallel, Wait, Pass, Choice } from 'asl-types';
77

@@ -66,20 +66,22 @@ export default class StepFunctionsOfflinePlugin implements Plugin {
6666
options: Options;
6767
commands: Plugin['commands'];
6868
hooks: Plugin['hooks'];
69+
cli: Logging;
6970
stateMachine: Options['stateMachine'];
7071

7172
environment = '';
7273

73-
constructor(serverless: ServerlessWithError, options: Options) {
74+
constructor(serverless: ServerlessWithError, options: Options, cli: Logging) {
7475
this.location = process.cwd();
7576
this.serverless = serverless;
77+
this.cli = cli;
7678
this.options = options;
7779
this.stateMachine = this.options.stateMachine;
7880
this.detailedLog = (this.options.detailedLog || this.options.l) ?? false;
7981
this.eventFile = this.options.event || this.options.e;
8082
this.functions = this.serverless.service.functions;
8183
this.variables = this.serverless.service.custom?.stepFunctionsOffline;
82-
this.cliLog = this.serverless.cli.log.bind(this.serverless.cli);
84+
this.cliLog = this.cli.log.info.bind(this.cli);
8385
this.contexts = {};
8486
this.commands = {
8587
'step-functions-offline': {

0 commit comments

Comments
 (0)