Skip to content

Commit

Permalink
feat: add support for ISC-declared flags
Browse files Browse the repository at this point in the history
  • Loading branch information
netlify-team-account-1 committed Dec 14, 2021
1 parent 78f6bbb commit c6fa092
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
11 changes: 3 additions & 8 deletions src/lib/functions/runtimes/js/builders/zisi.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const buildFunction = async ({ cache, config, directory, func, hasTypeModule, pr
archiveFormat: 'none',
basePath: projectRoot,
config,
featureFlags: {
parseISC: true,
},
}
const functionDirectory = path.dirname(func.mainFile)

Expand Down Expand Up @@ -100,14 +103,6 @@ module.exports = async ({ config, directory, errorExit, func, projectRoot }) =>
functionsConfig['*'].nodeBundler = 'esbuild'
}

// TODO: Resolve functions config globs so that we can check for the bundler
// on a per-function basis.
const isUsingEsbuild = ['esbuild_zisi', 'esbuild'].includes(functionsConfig['*'].nodeBundler)

if (!isUsingEsbuild) {
return false
}

// Enable source map support.
sourceMapSupport.install()

Expand Down
52 changes: 51 additions & 1 deletion tests/command.functions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ const testMatrix = [{ node_bundler: undefined }, { node_bundler: 'esbuild' }]
testMatrix.forEach((args) => {
const testName = (title) => `${title} - ${JSON.stringify(args)}`

test(testName('should only allow scheduled functions to be called via invoke'), async (t) => {
test(testName('should allow config-defined scheduled functions to only be called via invoke'), async (t) => {
await withSiteBuilder('site-with-ping-function', async (builder) => {
await builder
.withNetlifyToml({
Expand All @@ -577,6 +577,7 @@ testMatrix.forEach((args) => {
path: 'hello-world.js',
handler: async () => {
console.log('hello world')
return { statusCode: 200 }
},
})
.buildAsync()
Expand All @@ -586,6 +587,55 @@ testMatrix.forEach((args) => {
throwHttpErrors: false,
retry: null,
})
t.is(response.body, 'Scheduled functions can only be invoked using `netlify functions:invoke`.')
t.is(response.statusCode, 400)

const stdout = await callCli(['functions:invoke', 'hello-world', '--identity', `--port=${server.port}`], {
cwd: builder.directory,
stdio: 'inherit',
})
t.is(stdout, undefined)
})
})
})

test(testName('should allow ISC-defined scheduled functions to only be called via invoke'), async (t) => {
await withSiteBuilder('site-with-isc-ping-function', async (builder) => {
await builder
.withNetlifyToml({
config: { functions: { directory: 'functions' } },
})
// mocking until https://github.com/netlify/functions/pull/226 landed
.withContentFile({
path: 'node_modules/@netlify/functions/package.json',
content: `{}`,
})
.withContentFile({
path: 'node_modules/@netlify/functions/index.js',
content: `
module.exports.schedule = (schedule, handler) => handler
`,
})
.withContentFile({
path: 'functions/hello-world.js',
content: `
const { schedule } = require('@netlify/functions')
module.exports.handler = schedule('@daily', () => {
return {
statusCode: 200
}
})
`.trim(),
})
.buildAsync()

await withDevServer({ cwd: builder.directory }, async (server) => {
const response = await got(`http://localhost:${server.port}/.netlify/functions/hello-world`, {
throwHttpErrors: false,
retry: null,
})
t.is(response.body, 'Scheduled functions can only be invoked using `netlify functions:invoke`.')
t.is(response.statusCode, 400)

const stdout = await callCli(['functions:invoke', 'hello-world', '--identity', `--port=${server.port}`], {
Expand Down

0 comments on commit c6fa092

Please sign in to comment.