Skip to content

Commit

Permalink
fix: functions with name matching config prop cause crash (#4748)
Browse files Browse the repository at this point in the history
* fix: functions with name matching config prop cause crash

* fix: add test

* fix: add unit test, remove integration test

* fix: fix test name

* fix: refactor tests

* chore: clean up code

* fix: clean up code

* Update tests/unit/lib/functions/registry.test.js

Co-authored-by: Daniel Tschinder <[email protected]>

* fix: remove IO from test

* chore: update contributors field

Co-authored-by: Daniel Tschinder <[email protected]>
Co-authored-by: JWhist <[email protected]>
  • Loading branch information
3 people authored Jul 11, 2022
1 parent 22fd4d4 commit 19aee7c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/lib/functions/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ class FunctionsRegistry {
}

await Promise.all(directories.map((path) => FunctionsRegistry.prepareDirectoryScan(path)))

const functions = await this.listFunctions(directories, {
featureFlags: {
buildRustSource: env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE === 'true',
},
config: this.config,
config: this.config.functions,
})

// Before registering any functions, we look for any functions that were on
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/lib/functions/registry.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const test = require('ava')
const sinon = require('sinon')

const { FunctionsRegistry } = require('../../../../src/lib/functions/registry')

test('registry should only pass functions config to zip-it-and-ship-it', async (t) => {
const functionsRegistry = new FunctionsRegistry({
projectRoot: '/projectRoot',
config: { functions: { '*': {} }, plugins: ['test'] },
})
const prepareDirectoryScanStub = sinon.stub(FunctionsRegistry, 'prepareDirectoryScan')
const setupDirectoryWatcherStub = sinon.stub(functionsRegistry, 'setupDirectoryWatcher')
// To verify that only the functions config is passed to zip-it-ship-it
const listFunctionsStub = sinon.stub(functionsRegistry, 'listFunctions')
listFunctionsStub.returns(Promise.resolve([]))

await functionsRegistry.scan([functionsRegistry.projectRoot])

const spyCall = listFunctionsStub.getCall(0)

t.is(spyCall.lastArg.config, functionsRegistry.config.functions)

t.teardown(async () => {
await listFunctionsStub.restore()
await setupDirectoryWatcherStub.restore()
await prepareDirectoryScanStub.restore()
})
})

4 comments on commit 19aee7c

@github-actions
Copy link

Choose a reason for hiding this comment

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

πŸ“Š Benchmark results

Package size: 227 MB

@github-actions
Copy link

Choose a reason for hiding this comment

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

πŸ“Š Benchmark results

Package size: 227 MB

@github-actions
Copy link

Choose a reason for hiding this comment

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

πŸ“Š Benchmark results

Package size: 227 MB

@github-actions
Copy link

Choose a reason for hiding this comment

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

πŸ“Š Benchmark results

Package size: 227 MB

Please sign in to comment.