Skip to content

Commit 93a1662

Browse files
Lukas Holzererezrokahkodiakhq[bot]
authored
fix(functions): fixes an issue where the functions could not be served (#3863)
* fix(functions): fixes an issue where the functions could not be served * chore: solve in a more elegant fashion 💅 * chore: tests were writing on the real fs avoid that * chore: update test to only stub the mkdir function Co-authored-by: Erez Rokah <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent ecfc91f commit 93a1662

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/lib/functions/registry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @ts-check
22
const { mkdir } = require('fs').promises
3+
const { isAbsolute, join } = require('path')
34
const { env } = require('process')
45

56
const terminalLink = require('terminal-link')
@@ -146,7 +147,10 @@ class FunctionsRegistry {
146147
log(`${NETLIFYDEVLOG} ${chalk.green('Loaded')} function ${terminalLink(chalk.yellow(name), func.url)}.`)
147148
}
148149

149-
async scan(directories) {
150+
async scan(relativeDirs) {
151+
const directories = relativeDirs.filter(Boolean).map((dir) => (isAbsolute(dir) ? dir : join(this.projectRoot, dir)))
152+
153+
// check after filtering to filter out [undefined] for example
150154
if (directories.length === 0) {
151155
return
152156
}

src/lib/functions/server.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require('fs')
12
const { platform } = require('os')
23
const { join } = require('path')
34

@@ -8,12 +9,15 @@ const mockRequire = require('mock-require')
89
const sinon = require('sinon')
910
const request = require('supertest')
1011

11-
const { FunctionsRegistry } = require('./registry')
12-
const { createHandler } = require('./server')
13-
1412
const projectRoot = platform() === 'win32' ? 'C:\\my-functions' : `/my-functions`
1513
const functionsPath = `functions`
1614

15+
// mock mkdir for the functions folder
16+
sinon.stub(fs.promises, 'mkdir').withArgs(join(projectRoot, functionsPath)).returns(Promise.resolve())
17+
18+
const { FunctionsRegistry } = require('./registry')
19+
const { createHandler } = require('./server')
20+
1721
/** @type { express.Express} */
1822
let app
1923

0 commit comments

Comments
 (0)