Skip to content

Commit

Permalink
fix: layer name (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
echosoar committed Aug 5, 2020
1 parent 76bd23b commit 9a774b7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/serverless-spec-builder/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getLayers(...layersList: any) {
continue;
}
for (const layerName in typeLayerMap) {
const name = `layer_${type}_${layerName}`;
const name = `layer_${type}_${layerName.replace(/[^\w]/g, '_')}`;
layerDeps.push({
name,
type,
Expand Down
38 changes: 38 additions & 0 deletions packages/serverless-spec-builder/test/fixtures/wrapper/aggre.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
const { FaaSStarter } = require('@midwayjs/faas');
const { asyncWrapper, start } = require('testStarter');

const { registerFunctionToIocByConfig } = require('./registerFunction.js');
const { join } = require('path');

const picomatch = require('picomatch');
const layers = [];

try {
const layer_npm_testNpm = require('test');
layers.push(layer_npm_testNpm);
} catch(e) {
console.error('npm layer "test" not install', e);
}

try {
const layer_oss_remote_debug = require('remote-debug');
layers.push(layer_oss_remote_debug);
} catch(e) {
console.error('oss layer "remote-debug" not install', e);
}

try {
const layer_oss_testOss = require('test');
layers.push(layer_oss_testOss);
} catch(e) {
console.error('oss layer "test" not install', e);
}


let starter;
let runtime;
Expand All @@ -22,6 +46,20 @@ const initializeMethod = async (initializeContext = {}) => {
] });


registerFunctionToIocByConfig({
"functionList": [
{
"functionName": "test",
"functionHandler": "index.handler",
"functionFilePath": "fun-index.js",
"argsPath": "ctx.request.data.args"
}
]
}, {
baseDir: join(__dirname, 'dist'),
context: starter.loader.getApplicationContext()
});

await starter.start();
inited = true;

Expand Down
4 changes: 4 additions & 0 deletions packages/serverless-spec-builder/test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ describe('/test/wrapper.test.ts', () => {
testNpm: {
path: 'npm:test',
},
'remote-debug': {
path: 'oss:remote-debug',
},
testOss: {
path: 'oss:test',
},
Expand All @@ -125,6 +128,7 @@ describe('/test/wrapper.test.ts', () => {
readFileSync(aggrePath).toString()
)
);
assert(/layer_oss_remote_debug/.test(readFileSync(aggrePath).toString()));
await remove(registerFunction);
});
it('writeWrapper', async () => {
Expand Down

0 comments on commit 9a774b7

Please sign in to comment.