Skip to content

Commit

Permalink
Convert tests to jest dialect
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuunguyeen committed Mar 29, 2022
1 parent 219b5de commit 3e96143
Showing 1 changed file with 43 additions and 39 deletions.
82 changes: 43 additions & 39 deletions tests/compile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('compile', () => {
},
modules: []
},
toString: sandbox.stub().returns('testStats'),
toString: jest.fn().mockReturnValue('testStats'),
hasErrors: _.constant(false)
}
]
Expand All @@ -143,21 +143,23 @@ describe('compile', () => {
}
}
];
webpackMock.compilerMock.run.reset();
webpackMock.compilerMock.run.yields(null, multiStats);
return expect(module.compile()).to.be.fulfilled.then(() => {
expect(webpackMock).to.have.been.calledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name'
},
entry: {
'function-name/handler': './function-name/handler.js'
}
webpackMock.compilerMock.run.mockClear();
webpackMock.compilerMock.run.mockImplementation(cb => cb(null, multiStats));
return expect(module.compile())
.resolves.toBeUndefined()
.then(() => {
expect(webpackMock).toHaveBeenCalledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name'
},
entry: {
'function-name/handler': './function-name/handler.js'
}
});
expect(webpackMock.compilerMock.run).toHaveBeenCalledTimes(1);
return null;
});
expect(webpackMock.compilerMock.run).to.have.been.calledOnce;
return null;
});
});

it('should work with concurrent compile', () => {
Expand Down Expand Up @@ -224,7 +226,7 @@ describe('compile', () => {
},
modules: []
},
toString: sandbox.stub().returns('testStats'),
toString: jest.fn().mockReturnValue('testStats'),
hasErrors: _.constant(false)
}
]
Expand Down Expand Up @@ -260,30 +262,32 @@ describe('compile', () => {
}
}
];
webpackMock.compilerMock.run.reset();
webpackMock.compilerMock.run.yields(null, multiStats);
return expect(module.compile()).to.be.fulfilled.then(() => {
expect(webpackMock).to.have.been.calledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name-1'
},
entry: {
'function-name-1/handler': './function-name-1/handler.js'
}
});
expect(webpackMock).to.have.been.calledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name-2'
},
entry: {
'function-name-2/handler': './function-name-2/handler.js'
}
webpackMock.compilerMock.run.mockClear();
webpackMock.compilerMock.run.mockImplementation(cb => cb(null, multiStats));
return expect(module.compile())
.resolves.toBeUndefined()
.then(() => {
expect(webpackMock).toHaveBeenCalledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name-1'
},
entry: {
'function-name-1/handler': './function-name-1/handler.js'
}
});
expect(webpackMock).toHaveBeenCalledWith({
cache: {
type: 'filesystem',
name: 'service-stage-function-name-2'
},
entry: {
'function-name-2/handler': './function-name-2/handler.js'
}
});
expect(webpackMock.compilerMock.run).toHaveBeenCalledTimes(2);
return null;
});
expect(webpackMock.compilerMock.run).to.have.been.calledTwice;
return null;
});
});

it('should use correct stats option', () => {
Expand Down

0 comments on commit 3e96143

Please sign in to comment.