@@ -5,11 +5,12 @@ const fs = require('fs');
55const axios = require ( 'axios' ) ;
66const { expect } = require ( 'chai' ) ;
77const { expect : jestExpect } = require ( '@jest/globals' ) ;
8- const { execSync } = require ( '../utils/child-process' ) ;
8+
99const { getTmpDirPath, replaceTextInFile } = require ( '../utils/fs' ) ;
1010const { getServiceName, sleep } = require ( '../utils/misc' ) ;
1111const { FunctionApi, RegistryApi } = require ( '../../shared/api' ) ;
1212const { FUNCTIONS_API_URL , REGISTRY_API_URL } = require ( '../../shared/constants' ) ;
13+ const { execSync, execCaptureOutput } = require ( '../../shared/child-process' ) ;
1314const { validateRuntime } = require ( '../../deploy/lib/createFunctions' ) ;
1415
1516const serverlessExec = path . join ( 'serverless' ) ;
@@ -27,6 +28,7 @@ describe('Service Lifecyle Integration Test', () => {
2728 let api ;
2829 let registryApi ;
2930 let namespace ;
31+ let functionName ;
3032
3133 beforeAll ( ( ) => {
3234 oldCwd = process . cwd ( ) ;
@@ -55,35 +57,37 @@ describe('Service Lifecyle Integration Test', () => {
5557 execSync ( `${ serverlessExec } deploy` ) ;
5658 namespace = await api . getNamespaceFromList ( serviceName ) ;
5759 namespace . functions = await api . listFunctions ( namespace . id ) ;
60+ functionName = namespace . functions [ 0 ] . name ;
5861 } ) ;
5962
6063 it ( 'should invoke function from scaleway' , async ( ) => {
64+ // TODO query function status instead of having an arbitrary sleep
6165 await sleep ( 30000 ) ;
62- const deployedFunction = namespace . functions [ 0 ] ;
63- const response = await axios . get ( `https:// ${ deployedFunction . domain_name } ` ) ;
64- expect ( response . data . message ) . to . be . equal ( 'Hello from Serverless Framework and Scaleway Functions :D' ) ;
66+
67+ let output = execCaptureOutput ( serverlessExec , [ 'invoke' , '--function' , functionName ] ) ;
68+ expect ( output ) . to . be . equal ( '{"message":" Hello from Serverless Framework and Scaleway Functions :D"} ' ) ;
6569 } ) ;
6670
6771 it ( 'should deploy updated service to scaleway' , ( ) => {
68- const newHandler = `
69- 'use strict';
72+ const newJsHandler = `
73+ 'use strict';
7074
71- module.exports.handle = (event, context, cb) => {
72- return {
73- body: { message: 'Serverless Update Succeeded' }
74- };
75- }
76- `;
75+ module.exports.handle = (event, context, cb) => {
76+ return {
77+ message: 'Serverless Update Succeeded',
78+ };
79+ };
80+ ` ;
7781
78- fs . writeFileSync ( path . join ( tmpDir , 'handler.js' ) , newHandler ) ;
82+ fs . writeFileSync ( path . join ( tmpDir , 'handler.js' ) , newJsHandler ) ;
7983 execSync ( `${ serverlessExec } deploy` ) ;
8084 } ) ;
8185
8286 it ( 'should invoke updated function from scaleway' , async ( ) => {
8387 await sleep ( 30000 ) ;
84- const deployedFunction = namespace . functions [ 0 ] ;
85- const response = await axios . get ( `https:// ${ deployedFunction . domain_name } ` ) ;
86- expect ( response . data . body . message ) . to . be . equal ( 'Serverless Update Succeeded' ) ;
88+
89+ let output = execCaptureOutput ( serverlessExec , [ 'invoke' , '--function' , functionName ] ) ;
90+ expect ( output ) . to . be . equal ( '{"message":" Serverless Update Succeeded"} ' ) ;
8791 } ) ;
8892
8993 it ( 'should deploy function with another available runtime' , async ( ) => {
@@ -100,16 +104,16 @@ def handle(event, context):
100104 return {
101105 "message": "Hello From Python310 runtime on Serverless Framework and Scaleway Functions"
102106 }
103- `;
107+ ` ;
104108 fs . writeFileSync ( path . join ( tmpDir , 'handler.py' ) , pythonHandler ) ;
105109 execSync ( `${ serverlessExec } deploy` ) ;
106110 } ) ;
107111
108112 it ( 'should invoke function with runtime updated from scaleway' , async ( ) => {
109113 await sleep ( 30000 ) ;
110- const deployedFunction = namespace . functions [ 0 ] ;
111- const response = await axios . get ( `https:// ${ deployedFunction . domain_name } ` ) ;
112- expect ( response . data . message ) . to . be . equal ( 'Hello From Python310 runtime on Serverless Framework and Scaleway Functions' ) ;
114+
115+ let output = execCaptureOutput ( serverlessExec , [ 'invoke' , '--function' , functionName ] ) ;
116+ expect ( output ) . to . be . equal ( '{"message":" Hello From Python310 runtime on Serverless Framework and Scaleway Functions"} ' ) ;
113117 } ) ;
114118
115119 it ( 'should remove service from scaleway' , async ( ) => {
0 commit comments