UNPKG

1.36 kBJavaScriptView Raw
1const expect = require( "chai" ).expect;
2const assert = require( "chai" ).assert;
3const fs = require('fs-extra')
4
5const initLambda = require( "../lib/init-lambda" );
6
7const newLambdaPath = `${process.cwd()}/test-init-lambda`;
8
9function getFile ( path ) {
10 return fs.readFileSync( path ).toString().trim()
11}
12
13describe( "colly init-lambda", () => {
14
15 before( () => {
16 fs.removeSync( newLambdaPath );
17 });
18
19 after( () => {
20 fs.removeSync( newLambdaPath );
21 });
22
23 it( "should create a new directory with the right stuff in it", ( done ) => {
24
25 initLambda( "test-init-lambda" )
26 .then( ( response ) => {
27 expect( response ).to.equal( "Lambda \"test-init-lambda\" created!" );
28 expect( getFile( `${newLambdaPath}/index.js` ) ).to.equal( getFile( "./test/fixtures/init-lambda/index.js" ) );
29 expect( getFile( `${newLambdaPath}/function.json` ) ).to.equal( getFile( "./test/fixtures/init-lambda/function.json" ) );
30 done();
31 })
32 .catch( () => {
33 assert.fail();
34 done();
35 });
36
37 });
38
39 it( "should return an error if the directory already exists", ( done ) => {
40
41 initLambda( "test-init-lambda" )
42 .then( ( response ) => {
43 assert.fail( "actual", "expected" );
44 done();
45 })
46 .catch( ( response ) => {
47 expect( response ).to.equal( "Lambda \"test-init-lambda\" already exists" );
48 done();
49 });
50
51 });
52
53});