Skip to content

Commit

Permalink
feat: add new top-level schedule property (#819)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Nov 18, 2021
1 parent eddf2a3 commit 1da8089
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/manifest.ts
Expand Up @@ -36,12 +36,12 @@ const createManifest = async ({ functions, path }: { functions: FunctionResult[]
await writeFile(path, JSON.stringify(payload))
}

const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }: FunctionResult): ManifestFunction => ({
const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }: FunctionResult): ManifestFunction => ({
mainFile,
name,
path: resolve(path),
runtime,
schedule: config.schedule,
schedule,
})

export { createManifest }
Expand Down
3 changes: 2 additions & 1 deletion src/utils/format_result.ts
Expand Up @@ -3,13 +3,14 @@ import { RuntimeName } from '../runtimes/runtime'

import { removeUndefined } from './remove_undefined'

type FunctionResult = Omit<FunctionArchive, 'runtime'> & { runtime: RuntimeName }
type FunctionResult = Omit<FunctionArchive, 'runtime'> & { runtime: RuntimeName; schedule?: string }

// Takes the result of zipping a function and formats it for output.
const formatZipResult = (archive: FunctionArchive) => {
const functionResult: FunctionResult = {
...archive,
runtime: archive.runtime.name,
schedule: archive?.config?.schedule,
}

return removeUndefined(functionResult)
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/with-schedule/func-1.js
@@ -0,0 +1,3 @@
module.exports.handler = () => {
return true
}
29 changes: 29 additions & 0 deletions tests/main.js
Expand Up @@ -2353,6 +2353,35 @@ testMany(
},
)

testMany(
'Should surface schedule declarations on a top-level `schedule` property',
['bundler_default', 'bundler_default_nft', 'bundler_esbuild', 'bundler_nft'],
async (options, t) => {
const schedule = '* * * * *'
const fixtureName = 'with-schedule'
const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' })
const manifestPath = join(tmpDir, 'manifest.json')
const opts = merge(options, {
basePath: join(FIXTURES_DIR, fixtureName),
config: {
'*': {
schedule,
},
},
manifest: manifestPath,
})
const { files } = await zipNode(t, fixtureName, { opts })

files.every((file) => t.is(file.schedule, schedule))

const manifest = require(manifestPath)

manifest.functions.forEach((fn) => {
t.is(fn.schedule, schedule)
})
},
)

test('Generates a sourcemap for any transpiled files when `nodeSourcemap: true`', async (t) => {
const fixtureName = 'esm-throwing-error'
const basePath = join(FIXTURES_DIR, fixtureName)
Expand Down

1 comment on commit 1da8089

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏱ Benchmark results

largeDepsEsbuild: 8.2s

largeDepsNft: 52s

largeDepsZisi: 1m 6s

Please sign in to comment.