File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -9,9 +9,8 @@ function loadStatsFromFile(webpackOutputPath) {
9
9
const data = fs . readFileSync ( statsFile ) ;
10
10
const stats = JSON . parse ( data ) ;
11
11
12
- if ( ! stats . stats ) {
13
- const error = new this . serverless . classes . Error ( 'Packaging: No stats information found' ) ;
14
- throw error ;
12
+ if ( ! stats . stats || ! stats . stats . length ) {
13
+ throw new this . serverless . classes . Error ( 'Packaging: No stats information found' ) ;
15
14
}
16
15
17
16
const mappedStats = _ . map ( stats . stats , s =>
@@ -23,7 +22,7 @@ function loadStatsFromFile(webpackOutputPath) {
23
22
24
23
module . exports = {
25
24
get ( ) {
26
- const stats = this . stats || loadStatsFromFile ( this . webpackOutputPath ) ;
25
+ const stats = this . stats || loadStatsFromFile . call ( this , this . webpackOutputPath ) ;
27
26
28
27
return stats ;
29
28
} ,
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ const BbPromise = require('bluebird');
5
5
const chai = require ( 'chai' ) ;
6
6
const sinon = require ( 'sinon' ) ;
7
7
const path = require ( 'path' ) ;
8
+ const Serverless = require ( 'serverless' ) ;
8
9
9
10
// Mocks
10
11
const fsMockFactory = require ( '../tests/mocks/fs.mock' ) ;
@@ -19,6 +20,7 @@ describe('compileStats', () => {
19
20
let baseModule ;
20
21
let module ;
21
22
let sandbox ;
23
+ let serverless ;
22
24
let fsMock ;
23
25
24
26
before ( ( ) => {
@@ -35,8 +37,13 @@ describe('compileStats', () => {
35
37
} ) ;
36
38
37
39
beforeEach ( ( ) => {
40
+ serverless = new Serverless ( ) ;
41
+ serverless . cli = {
42
+ log : sandbox . stub ( )
43
+ } ;
38
44
module = _ . assign (
39
45
{
46
+ serverless,
40
47
options : { }
41
48
} ,
42
49
baseModule
@@ -79,15 +86,15 @@ describe('compileStats', () => {
79
86
it ( 'should fail if compile stats are not loaded' , ( ) => {
80
87
const webpackOutputPath = '.webpack' ;
81
88
82
- const statsFile = { } ;
89
+ const statsFile = { stats : [ ] } ;
83
90
84
91
module . webpackOutputPath = webpackOutputPath ;
85
92
86
93
const fullStatsPath = `${ webpackOutputPath } /stats.json` ;
87
94
88
95
fsMock . readFileSync . withArgs ( fullStatsPath ) . returns ( JSON . stringify ( statsFile ) ) ;
89
96
90
- expect ( ( ) => module . get ( ) ) . throws ( ) ;
97
+ expect ( ( ) => module . get ( ) ) . to . throw ( / P a c k a g i n g : N o s t a t s i n f o r m a t i o n f o u n d / ) ;
91
98
} ) ;
92
99
} ) ;
93
100
You can’t perform that action at this time.
0 commit comments