Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

feat: add new top-level schedule property #819

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/manifest.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.handler = () => {
return true
}
29 changes: 29 additions & 0 deletions tests/main.js
Original file line number Diff line number Diff line change
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