UNPKG

1.44 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 process.env.COLLY__LAMBDA_NAME = "test-init-lambda";
26 process.env.COLLY__PROJECT_DIR = process.cwd();
27
28 initLambda()
29 .then( ( response ) => {
30 expect( response ).to.equal( "Lambda \"test-init-lambda\" created!" );
31 expect( getFile( `${newLambdaPath}/index.js` ) ).to.equal( getFile( "./test/fixtures/init-lambda/index.js" ) );
32 expect( getFile( `${newLambdaPath}/function.json` ) ).to.equal( getFile( "./test/fixtures/init-lambda/function.json" ) );
33 done();
34 })
35 .catch( () => {
36 assert.fail();
37 done();
38 });
39
40 });
41
42 it( "should return an error if the directory already exists", ( done ) => {
43
44 initLambda( "test-init-lambda" )
45 .then( ( response ) => {
46 assert.fail( "actual", "expected" );
47 done();
48 })
49 .catch( ( response ) => {
50 expect( response ).to.equal( "Lambda \"test-init-lambda\" already exists" );
51 done();
52 });
53
54 });
55
56});