Skip to content

Commit

Permalink
fix(functions): fixes an issue where the functions could not be served (
Browse files Browse the repository at this point in the history
#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 <erezrokah@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 7, 2022
1 parent ecfc91f commit 93a1662
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/lib/functions/registry.js
@@ -1,5 +1,6 @@
// @ts-check
const { mkdir } = require('fs').promises
const { isAbsolute, join } = require('path')
const { env } = require('process')

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

async scan(directories) {
async scan(relativeDirs) {
const directories = relativeDirs.filter(Boolean).map((dir) => (isAbsolute(dir) ? dir : join(this.projectRoot, dir)))

// check after filtering to filter out [undefined] for example
if (directories.length === 0) {
return
}
Expand Down
10 changes: 7 additions & 3 deletions src/lib/functions/server.test.js
@@ -1,3 +1,4 @@
const fs = require('fs')
const { platform } = require('os')
const { join } = require('path')

Expand All @@ -8,12 +9,15 @@ const mockRequire = require('mock-require')
const sinon = require('sinon')
const request = require('supertest')

const { FunctionsRegistry } = require('./registry')
const { createHandler } = require('./server')

const projectRoot = platform() === 'win32' ? 'C:\\my-functions' : `/my-functions`
const functionsPath = `functions`

// mock mkdir for the functions folder
sinon.stub(fs.promises, 'mkdir').withArgs(join(projectRoot, functionsPath)).returns(Promise.resolve())

const { FunctionsRegistry } = require('./registry')
const { createHandler } = require('./server')

/** @type { express.Express} */
let app

Expand Down

1 comment on commit 93a1662

@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: 356 MB

Please sign in to comment.