@@ -6,6 +6,8 @@ const originalRunServerless = require('@serverless/test/run-serverless');
66const { spawnProcess } = require ( '../../lib/utils' ) ;
77
88const FIXTURES_DIR = path . resolve ( __dirname , '..' , '..' , 'examples' ) ;
9+ const PROJECT_DIR = path . resolve ( __dirname , '..' , '..' ) ;
10+ let pluginPackagePathPromise ;
911
1012async function replaceInFile ( path , regex , replacement ) {
1113 const content = await fse . readFile ( path , 'utf8' ) ;
@@ -16,15 +18,39 @@ async function replaceInFile(path, regex, replacement) {
1618async function setupFixture ( name ) {
1719 const fixturePath = path . join ( FIXTURES_DIR , name ) ;
1820 const setupFixturePath = await provisionTmpDir ( ) ;
21+ const pluginPackagePath = await getPluginPackagePath ( ) ;
1922 await fse . copy ( fixturePath , setupFixturePath ) ;
2023
2124 const setupScriptPath = path . resolve ( setupFixturePath , '_setup.js' ) ;
22- await require ( setupScriptPath ) ( fixturePath , setupFixturePath , { replaceInFile, spawnProcess } ) ;
25+ await require ( setupScriptPath ) ( fixturePath , setupFixturePath , {
26+ pluginPackagePath,
27+ replaceInFile,
28+ spawnProcess
29+ } ) ;
2330 await fse . unlink ( setupScriptPath ) ;
2431
2532 return setupFixturePath ;
2633}
2734
35+ async function getPluginPackagePath ( ) {
36+ if ( ! pluginPackagePathPromise ) {
37+ pluginPackagePathPromise = ( async ( ) => {
38+ const packageDir = await provisionTmpDir ( ) ;
39+ const npmCommand = / ^ w i n / . test ( process . platform ) ? 'npm.cmd' : 'npm' ;
40+ const { stdout } = await spawnProcess (
41+ npmCommand ,
42+ [ 'pack' , '--pack-destination' , packageDir , '--cache' , path . join ( packageDir , '.npm-cache' ) ] ,
43+ { cwd : PROJECT_DIR }
44+ ) ;
45+ const packageFile = stdout . trim ( ) . split ( / \r ? \n / ) . pop ( ) ;
46+
47+ return path . join ( packageDir , packageFile ) ;
48+ } ) ( ) ;
49+ }
50+
51+ return pluginPackagePathPromise ;
52+ }
53+
2854async function runServerless ( options ) {
2955 const runServerlessOptions = {
3056 command : 'package'
0 commit comments