{"size": 1816, "ext": "js", "max_stars_repo_path": "packages/build/tests/functions/tests.js", "max_stars_repo_name": "netlify/build", "max_stars_repo_stars_event_min_datetime": "2019-10-16T21:49:25.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-20T11:31:32.000Z", "max_issues_repo_path": "packages/build/tests/functions/tests.js", "max_issues_repo_name": "netlify/build", "max_issues_repo_issues_event_min_datetime": "2019-10-16T23:14:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-24T20:07:03.000Z", "max_forks_repo_path": "packages/build/tests/functions/tests.js", "max_forks_repo_name": "netlify/build", "max_forks_repo_forks_event_min_datetime": "2019-10-17T17:54:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-24T22:30:39.000Z"}
{"max_stars_count": 171, "max_issues_count": 1838, "max_forks_count": 44, "avg_line_length": 28.375, "max_line_length": 84, "alphanum_fraction": 0.6899779736}
import { writeFile, readdir } from 'fs'
import { promisify } from 'util'

import test from 'ava'
import del from 'del'
import pathExists from 'path-exists'

import { removeDir } from '../helpers/dir.js'
import { runFixture, FIXTURES_DIR } from '../helpers/main.js'
import { getTempName } from '../helpers/temp.js'

const pWriteFile = promisify(writeFile)
const pReaddir = promisify(readdir)

test('Functions: missing source directory', async (t) => {
  await runFixture(t, 'missing')
})

test('Functions: must not be a regular file', async (t) => {
  await runFixture(t, 'regular_file')
})

test('Functions: can be a symbolic link', async (t) => {
  await runFixture(t, 'symlink')
})

test('Functions: default directory', async (t) => {
  await runFixture(t, 'default')
})

test('Functions: simple setup', async (t) => {
  await removeDir(`${FIXTURES_DIR}/simple/.netlify/functions/`)
  await runFixture(t, 'simple')
})

test('Functions: no functions', async (t) => {
  await runFixture(t, 'none')
})

test('Functions: invalid package.json', async (t) => {
  const fixtureName = 'functions_package_json_invalid'
  const packageJsonPath = `${FIXTURES_DIR}/${fixtureName}/package.json`
  // We need to create that file during tests. Otherwise, ESLint fails when
  // detecting an invalid *.json file.
  await pWriteFile(packageJsonPath, '{{}')
  try {
    await runFixture(t, fixtureName)
  } finally {
    await del(packageJsonPath)
  }
})

test('Functions: --functionsDistDir', async (t) => {
  const functionsDistDir = await getTempName()
  try {
    await runFixture(t, 'simple', { flags: { mode: 'buildbot', functionsDistDir } })
    t.true(await pathExists(functionsDistDir))
    const files = await pReaddir(functionsDistDir)
    t.is(files.length, 1)
  } finally {
    await removeDir(functionsDistDir)
  }
})
