From 328d10c28260105ff66fbd1e538c62970587926e Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:07:49 -0600 Subject: [PATCH 01/14] refactor: move and rename test file --- .../framework-detection.test.cjs} | 12 ++++++------ .../snapshots/framework-detection.test.cjs.md} | 4 ++-- .../snapshots/framework-detection.test.cjs.snap} | Bin 3 files changed, 8 insertions(+), 8 deletions(-) rename tests/integration/{600.framework-detection.test.cjs => frameworks/framework-detection.test.cjs} (97%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.md => frameworks/snapshots/framework-detection.test.cjs.md} (98%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.snap => frameworks/snapshots/framework-detection.test.cjs.snap} (100%) diff --git a/tests/integration/600.framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.cjs similarity index 97% rename from tests/integration/600.framework-detection.test.cjs rename to tests/integration/frameworks/framework-detection.test.cjs index d85d59c54cd..37e88d7cefa 100644 --- a/tests/integration/600.framework-detection.test.cjs +++ b/tests/integration/frameworks/framework-detection.test.cjs @@ -3,12 +3,12 @@ const avaTest = require('ava') const { isCI } = require('ci-info') const execa = require('execa') -const cliPath = require('./utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('./utils/dev-server.cjs') -const got = require('./utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('./utils/handle-questions.cjs') -const { withSiteBuilder } = require('./utils/site-builder.cjs') -const { normalize } = require('./utils/snapshots.cjs') +const cliPath = require('../utils/cli-path.cjs') +const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') +const got = require('../utils/got.cjs') +const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') +const { withSiteBuilder } = require('../utils/site-builder.cjs') +const { normalize } = require('../utils/snapshots.cjs') const content = 'Hello World!' diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md similarity index 98% rename from tests/integration/snapshots/600.framework-detection.test.cjs.md rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.md index c4a0d807060..0f0f0f29083 100644 --- a/tests/integration/snapshots/600.framework-detection.test.cjs.md +++ b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `tests/integration/600.framework-detection.test.cjs` +# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` -The actual snapshot is saved in `600.framework-detection.test.cjs.snap`. +The actual snapshot is saved in `framework-detection.test.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap similarity index 100% rename from tests/integration/snapshots/600.framework-detection.test.cjs.snap rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap From 0a7a9df060fc6b8c93d5db35d78533b3b0a7880f Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:14:43 -0600 Subject: [PATCH 02/14] refactor: convert file to esm - convert file to esm - adjust file accordingly - update snapshots --- ....test.cjs => framework-detection.test.mjs} | 20 +++++++++--------- ...cjs.md => framework-detection.test.mjs.md} | 4 ++-- ...snap => framework-detection.test.mjs.snap} | Bin 3 files changed, 12 insertions(+), 12 deletions(-) rename tests/integration/frameworks/{framework-detection.test.cjs => framework-detection.test.mjs} (96%) rename tests/integration/frameworks/snapshots/{framework-detection.test.cjs.md => framework-detection.test.mjs.md} (99%) rename tests/integration/frameworks/snapshots/{framework-detection.test.cjs.snap => framework-detection.test.mjs.snap} (100%) diff --git a/tests/integration/frameworks/framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.mjs similarity index 96% rename from tests/integration/frameworks/framework-detection.test.cjs rename to tests/integration/frameworks/framework-detection.test.mjs index 37e88d7cefa..b30a0ca1c59 100644 --- a/tests/integration/frameworks/framework-detection.test.cjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,14 +1,14 @@ // eslint-disable-next-line ava/use-test -const avaTest = require('ava') -const { isCI } = require('ci-info') -const execa = require('execa') - -const cliPath = require('../utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') -const got = require('../utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') -const { withSiteBuilder } = require('../utils/site-builder.cjs') -const { normalize } = require('../utils/snapshots.cjs') +import avaTest from 'ava' +import { isCI } from 'ci-info' +import execa from 'execa' + +import cliPath from '../utils/cli-path.cjs' +import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' +import got from '../utils/got.cjs' +import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' +import { withSiteBuilder } from '../utils/site-builder.cjs' +import { normalize } from '../utils/snapshots.cjs' const content = 'Hello World!' diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md similarity index 99% rename from tests/integration/frameworks/snapshots/framework-detection.test.cjs.md rename to tests/integration/frameworks/snapshots/framework-detection.test.mjs.md index 0f0f0f29083..8c585dbd9d6 100644 --- a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md +++ b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` +# Snapshot report for `tests/integration/frameworks/framework-detection.test.mjs` -The actual snapshot is saved in `framework-detection.test.cjs.snap`. +The actual snapshot is saved in `framework-detection.test.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap similarity index 100% rename from tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap rename to tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap From c95aaaf20e3ef3a04922e03789278c7ee52ffb4c Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:48:49 -0600 Subject: [PATCH 03/14] refactor: replace ava with vitest - replace ava with vitest - run test concurrently - update snapshots --- .../framework-detection.test.mjs.snap | 268 +++++++++ .../frameworks/framework-detection.test.mjs | 568 +++++++++--------- .../snapshots/framework-detection.test.mjs.md | 308 ---------- .../framework-detection.test.mjs.snap | Bin 2149 -> 0 bytes 4 files changed, 551 insertions(+), 593 deletions(-) create mode 100644 tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.mjs.md delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap diff --git a/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap new file mode 100644 index 00000000000..4e826fbca37 --- /dev/null +++ b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap @@ -0,0 +1,268 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`frameworks/framework-detection > should default to process.cwd() and static server 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should detect a known framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App + +> start +> react-scripts start + +◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should filter frameworks with no dev command 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-gulp\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should force a specific framework when configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App +◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists" +`; + +exports[`frameworks/framework-detection > should log the command if using static server and \`command\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should not run framework detection if command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should pass framework-info env to framework sub process 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Nuxt 3 + +> dev +> node -p process.env.NODE_VERSION + +14 +◈ \\"npm run dev\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should print specific error when command doesn't exist 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists" +`; + +exports[`frameworks/framework-detection > should prompt when multiple frameworks are detected 1`] = ` +"◈ Netlify Dev ◈ +? Multiple possible start commands found (Use arrow keys or type to search) +> [Gatsby] 'npm run develop' + [Create React App] 'npm run start' ? Multiple possible start commands found + [Gatsby] 'npm run develop' +> [Create React App] 'npm run start' ? Multiple possible start commands found Create React App-npm run start +Add 'framework = \\"create-react-app\\"' to the [dev] section of your netlify.toml to avoid this selection prompt next time +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App + +> start +> react-scripts start + +◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should run \`command\` when both \`command\` and \`targetPort\` are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should run and serve a production build when using the \`serve\` command 1`] = ` +"◈ Injected netlify.toml file env var: CONTEXT_CHECK +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Running static server from \\"site-with-framework/public\\" +◈ Building site for production +◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again +​ +Netlify Build +──────────────────────────────────────────────────────────────── +​ +> Version + @netlify/build 0.0.0 +​ +> Flags + offline: true + outputConfigPath:/file/path +​ +> Current directory + /file/path +​ +> Config file + /file/path +​ +> Context + production +​ +> Loading plugins + -/file/path from netlify.toml +​ +/file/path (onPreBuild event) +──────────────────────────────────────────────────────────────── +​ +Netlify configuration property \\"redirects\\" value changed to [ { from: /file/path', to: /file/path' } ]. +​ +/file/path onPreBuild completed in Xms) +​ +Functions bundling +──────────────────────────────────────────────────────────────── +​ +Packaging Functions from new_functions directory: + - hello.js +​ +​ +(Functions bundling completed in Xms) +​ +Save deploy artifacts +──────────────────────────────────────────────────────────────── +​ +​ +(Save deploy artifacts completed in Xms) +​ +Netlify Build Complete +──────────────────────────────────────────────────────────────── +​ +(Netlify Build completed in Xms) + +◈ Static server listening to 88888 +◈ Loaded function hello http://localhost:88888/.netlify/functions/hello. +◈ Functions server is listening on 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should start custom command if framework=#custom, command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but command is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but targetPort is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw when forcing a non supported framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Invalid framework \\"to-infinity-and-beyond-js\\". It should be one of: *" +`; + +exports[`frameworks/framework-detection > should use static server when --dir flag is passed 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should use static server when framework is set to #static 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should warn if using static server and \`targetPort\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Ignoring 'targetPort' setting since using a simple static server. +◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index b30a0ca1c59..688db23c8ab 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,7 +1,5 @@ -// eslint-disable-next-line ava/use-test -import avaTest from 'ava' -import { isCI } from 'ci-info' import execa from 'execa' +import { describe, test } from 'vitest' import cliPath from '../utils/cli-path.cjs' import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' @@ -12,197 +10,196 @@ import { normalize } from '../utils/snapshots.cjs' const content = 'Hello World!' -const test = isCI ? avaTest.serial.bind(avaTest) : avaTest +describe.concurrent('frameworks/framework-detection', () => { + test('should default to process.cwd() and static server', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) -test('should default to process.cwd() and static server', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) }) }) -}) - -test('should use static server when --dir flag is passed', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should use static server when --dir flag is passed', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) + await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) -test('should use static server when framework is set to #static', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .withNetlifyToml({ config: { dev: { framework: '#static' } } }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) }) }) -}) - -test('should log the command if using static server and `command` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, - async ({ output, url }) => { + test('should use static server when framework is set to #static', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withNetlifyToml({ config: { dev: { framework: '#static' } } }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { const response = await got(url).text() - t.is(response, content) + t.expect(response).toEqual(content) - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) - }) -}) - -test('should warn if using static server and `targetPort` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .buildAsync() + }) + }) - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, - async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should log the command if using static server and `command` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) + }) - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) + test('should warn if using static server and `targetPort` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) }) -}) -test('should run `command` when both `command` and `targetPort` are configured', async (t) => { - await withSiteBuilder('empty-site', async (builder) => { - await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() + test('should run `command` when both `command` and `targetPort` are configured', async (t) => { + await withSiteBuilder('empty-site', async (builder) => { + await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() - // a failure is expected since we use `echo hello` instead of starting a server - const error = await t.throwsAsync(() => - withDevServer( + // a failure is expected since we use `echo hello` instead of starting a server + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should force a specific framework when configured', async (t) => { - await withSiteBuilder('site-with-mocked-cra', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() + test('should force a specific framework when configured', async (t) => { + await withSiteBuilder('site-with-mocked-cra', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw when forcing a non supported framework', async (t) => { - await withSiteBuilder('site-with-unknown-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() + test('should throw when forcing a non supported framework', async (t) => { + await withSiteBuilder('site-with-unknown-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) - -test('should detect a known framework', async (t) => { - await withSiteBuilder('site-with-cra', async (builder) => { - await builder - .withPackageJson({ - packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, - }) - .buildAsync() - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + test('should detect a known framework', async (t) => { + await withSiteBuilder('site-with-cra', async (builder) => { + await builder + .withPackageJson({ + packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, + }) + .buildAsync() + + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw if framework=#custom but command is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + test('should throw if framework=#custom but command is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer( + { cwd: builder.directory, args: ['--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw if framework=#custom but targetPort is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + test('should throw if framework=#custom but targetPort is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() + test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer( + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test(`should print specific error when command doesn't exist`, async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.buildAsync() + test(`should print specific error when command doesn't exist`, async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.buildAsync() - const error = await t.throwsAsync(() => - withDevServer( + const error = await withDevServer( { cwd: builder.directory, args: [ @@ -216,170 +213,171 @@ test(`should print specific error when command doesn't exist`, async (t) => { }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) + ).catch((error) => error) -test('should prompt when multiple frameworks are detected', async (t) => { - await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, - scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, - }, - }) - .withContentFile({ path: 'gatsby-config.js', content: '' }) - .buildAsync() - - // a failure is expected since this is not a true framework project - const error = await t.throwsAsync(async () => { - const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) - handleQuestions(childProcess, [ - { - question: 'Multiple possible start commands found', - answer: answerWithValue(DOWN), - }, - ]) + test('should prompt when multiple frameworks are detected', async (t) => { + await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, + scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, + }, + }) + .withContentFile({ path: 'gatsby-config.js', content: '' }) + .buildAsync() + + // a failure is expected since this is not a true framework project + const asyncErrorBlock = async () => { + const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) + + handleQuestions(childProcess, [ + { + question: 'Multiple possible start commands found', + answer: answerWithValue(DOWN), + }, + ]) - await childProcess + await childProcess + } + const error = await asyncErrorBlock().catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) }) -}) -test('should not run framework detection if command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-hugo-config', async (builder) => { - await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() + test('should not run framework detection if command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-hugo-config', async (builder) => { + await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() - // a failure is expected since the command exits early - const error = await t.throwsAsync(() => - withDevServer( + // a failure is expected since the command exits early + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) + ).catch((error) => error) -test('should filter frameworks with no dev command', async (t) => { - await withSiteBuilder('site-with-gulp', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, - }) - .withPackageJson({ - packageJson: { dependencies: { gulp: '1.0.0' } }, - }) - .buildAsync() + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should filter frameworks with no dev command', async (t) => { + await withSiteBuilder('site-with-gulp', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withPackageJson({ + packageJson: { dependencies: { gulp: '1.0.0' } }, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) - t.snapshot(normalize(output, { duration: true, filePath: true })) + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }) }) }) -}) -test('should pass framework-info env to framework sub process', async (t) => { - await withSiteBuilder('site-with-gatsby', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { nuxt3: '^2.0.0' }, - scripts: { dev: 'node -p process.env.NODE_VERSION' }, - }, - }) - .buildAsync() + test('should pass framework-info env to framework sub process', async (t) => { + await withSiteBuilder('site-with-gatsby', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { nuxt3: '^2.0.0' }, + scripts: { dev: 'node -p process.env.NODE_VERSION' }, + }, + }) + .buildAsync() - // a failure is expected since this is not a true Gatsby project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + // a failure is expected since this is not a true Gatsby project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should start static service for frameworks without port, forced framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() + test('should start static service for frameworks without port, forced framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) }) -}) -test('should start static service for frameworks without port, detected framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, - scripts: {}, - }, - }) - .withContentFile({ path: 'remix.config.js', content: '' }) - .buildAsync() + test('should start static service for frameworks without port, detected framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, + scripts: {}, + }, + }) + .withContentFile({ path: 'remix.config.js', content: '' }) + .buildAsync() - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) }) -}) -test('should run and serve a production build when using the `serve` command', async (t) => { - await withSiteBuilder('site-with-framework', async (builder) => { - await builder - .withNetlifyToml({ - config: { - build: { publish: 'public' }, - context: { - dev: { environment: { CONTEXT_CHECK: 'DEV' } }, - production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + test('should run and serve a production build when using the `serve` command', async (t) => { + await withSiteBuilder('site-with-framework', async (builder) => { + await builder + .withNetlifyToml({ + config: { + build: { publish: 'public' }, + context: { + dev: { environment: { CONTEXT_CHECK: 'DEV' } }, + production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + }, + functions: { directory: 'functions' }, + plugins: [{ package: './plugins/frameworker' }], }, - functions: { directory: 'functions' }, - plugins: [{ package: './plugins/frameworker' }], - }, - }) - .withBuildPlugin({ - name: 'frameworker', - plugin: { - onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require - const { mkdir, writeFile } = require('fs').promises - - const generatedFunctionsDir = 'new_functions' - netlifyConfig.functions.directory = generatedFunctionsDir - - netlifyConfig.redirects.push({ - from: '/hello', - to: '/.netlify/functions/hello', - }) - - await mkdir(generatedFunctionsDir) - await writeFile( - `${generatedFunctionsDir}/hello.js`, - `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, - ) + }) + .withBuildPlugin({ + name: 'frameworker', + plugin: { + onPreBuild: async ({ netlifyConfig }) => { + // eslint-disable-next-line n/global-require + const { mkdir, writeFile } = require('fs').promises + + const generatedFunctionsDir = 'new_functions' + netlifyConfig.functions.directory = generatedFunctionsDir + + netlifyConfig.redirects.push({ + from: '/hello', + to: '/.netlify/functions/hello', + }) + + await mkdir(generatedFunctionsDir) + await writeFile( + `${generatedFunctionsDir}/hello.js`, + `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, + ) + }, }, - }, - }) - .buildAsync() + }) + .buildAsync() - await withDevServer( - { cwd: builder.directory, context: null, debug: true, serve: true }, - async ({ output, url }) => { - const response = await got(`${url}/hello`).json() - t.deepEqual(response, { CONTEXT_CHECK: 'PRODUCTION' }) + await withDevServer( + { cwd: builder.directory, context: null, debug: true, serve: true }, + async ({ output, url }) => { + const response = await got(`${url}/hello`).json() + t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) }) }) diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md deleted file mode 100644 index 8c585dbd9d6..00000000000 --- a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md +++ /dev/null @@ -1,308 +0,0 @@ -# Snapshot report for `tests/integration/frameworks/framework-detection.test.mjs` - -The actual snapshot is saved in `framework-detection.test.mjs.snap`. - -Generated by [AVA](https://avajs.dev). - -## should default to process.cwd() and static server - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when --dir flag is passed - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when framework is set to #static - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should log the command if using static server and `command` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should warn if using static server and `targetPort` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Ignoring 'targetPort' setting since using a simple static server.␊ - ◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should run `command` when both `command` and `targetPort` are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should force a specific framework when configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists` - -## should throw when forcing a non supported framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Invalid framework "to-infinity-and-beyond-js". It should be one of: *` - -## should detect a known framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should throw if framework=#custom but command is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should throw if framework=#custom but targetPort is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should start custom command if framework=#custom, command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should print specific error when command doesn't exist - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - ◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists` - -## should prompt when multiple frameworks are detected - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ? Multiple possible start commands found (Use arrow keys or type to search)␊ - > [Gatsby] 'npm run develop' ␊ - [Create React App] 'npm run start' ? Multiple possible start commands found ␊ - [Gatsby] 'npm run develop' ␊ - > [Create React App] 'npm run start' ? Multiple possible start commands found Create React App-npm run start␊ - Add 'framework = "create-react-app"' to the [dev] section of your netlify.toml to avoid this selection prompt next time␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should not run framework detection if command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should filter frameworks with no dev command - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-gulp"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should pass framework-info env to framework sub process - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Nuxt 3␊ - ␊ - > dev␊ - > node -p process.env.NODE_VERSION␊ - ␊ - 14␊ - ◈ "npm run dev" exited with code *. Shutting down Netlify Dev server` - -## should run and serve a production build when using the `serve` command - -> Snapshot 1 - - `◈ Injected netlify.toml file env var: CONTEXT_CHECK␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Running static server from "site-with-framework/public"␊ - ◈ Building site for production␊ - ◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again␊ - ​␊ - Netlify Build ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - > Version␊ - @netlify/build 0.0.0␊ - ​␊ - > Flags␊ - offline: true␊ - outputConfigPath:/file/path␊ - ​␊ - > Current directory␊ - /file/path␊ - ​␊ - > Config file␊ - /file/path␊ - ​␊ - > Context␊ - production␊ - ​␊ - > Loading plugins␊ - -/file/path from netlify.toml␊ - ​␊ - /file/path (onPreBuild event) ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Netlify configuration property "redirects" value changed to [ { from: /file/path', to: /file/path' } ].␊ - ​␊ - /file/path onPreBuild completed in Xms)␊ - ​␊ - Functions bundling ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Packaging Functions from new_functions directory:␊ - - hello.js␊ - ​␊ - ​␊ - (Functions bundling completed in Xms)␊ - ​␊ - Save deploy artifacts ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - ​␊ - (Save deploy artifacts completed in Xms)␊ - ​␊ - Netlify Build Complete ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - (Netlify Build completed in Xms)␊ - ␊ - ◈ Static server listening to 88888␊ - ◈ Loaded function hello http://localhost:88888/.netlify/functions/hello.␊ - ◈ Functions server is listening on 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap deleted file mode 100644 index c2264d9a2ec80794bd3da5ccd8c9326ba4c9e7ae..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2149 zcmV-r2%7gnRzVd*|4-t8n2vKEWhgB?yw9;6`B zmzyk2CUA|90IwVNGYKruy&PQ9@W}AE1@G%r^g*Y?JmdAn?6mg<>){Plji#t!Dmdgt zFT+uZ%wiOUx9oUG(u`|JlpK~)qe3Yz42-2Zr0Y0UxT;hWEBX#MMGg#v)3#;gFtb8n zoSFgN*pK<>0EI^;mBOx*^N98}kp*pGRPIJ|V^F?sdAS^78EIgq0|R4n-D$U@ENztw zMRM5oe}^dL0)qYk7YQ9GxRw=jyAZ-cQ^mw?51KkPJR~i{RK)yYNLn|`O_3^qJ40i$ zjMU_r%!h=7$JGt2iOo`NxLppn`5HYM4FGuj=%2uGwp*h>k$8Zg!nr?#8n|GdC*qbJ&DES?6ZYHXNn&c z>39EF3-sTdSrzEVab@qx$_}gwu@!GrXsm&~GK~SxGHGWtc{Gq&_qWB~l@0u##t@N+)6=I|`1!)ZqBT3Bu7u?=~E6a~2uc&T~8b z215$5cDCW~&Dxflidl_d)dvs8Vf`i(afRNNim)KnP*qDLBz;gW= z!sKXGV2J4=C(gsgr)Vvrb67=Z<6spyJ7UDLv?2+bMj}ThsYuNv#2tk_K9TtLKsQ^k zgNQlpdK{x2Ur7gEE;aw!^w^f#7u5DpkQ*GK<$r26{Ksc$!^Tx-9DHA5GRO5@U+X5$ z)>aU?z4!MHh_X_NeW9NCnRI{LRHV}9%gK|UPKHi3A%l;qi>AQYU*0wWB zoOVA8Tf8*AORvgaKaJRbSBrvQpI{VtO;3W-zv3IRg8IkcBpTgnr6G zo?9YeRkp*84s+uiWmse;rS4%GVlIr!@8*^?L0_)<%zu|2B)kFNDFx>esi)`q6E!7T z^blE~gKkob!W2>2A)jb!P0S?c&YhTw1{X1D?7z*7?oAFLD3gFULI7B+?$76&$~e1b z0O$8#**?F2`O3BP`&Yiv#jCgQb@TlG)^`2mH%i)hE>I)vf2E)%==aZAIMt z79p_JZEVMJg`44ZXhwEw=<+km^JYLcpcb$me=>1#R|{7h$wo4zq-0q>^Mk#o3H}gy zKOOQfVu5kfN0pGqPM@JVB@#+uPnWMg+?Y#PYlc1nhCcBg>{8i-rJ1qkBvY=n;)Jvy zc^6qixqqrT!Ee{UulQ`g@97s=zCOBIA6-4aqpK@rDaN#((E%L>NZ?{bZZgXwy6Ba^ z$y#h^<|_CTY-n~1%;J|R*Wy(CUl0j~`Sj;vsCR4k*0t;RKDd7S&d#mfMq}$$N28Vc z=-GJmM&-oM{w~dO5+fDj!ZAp%NHgDjy7O@=VeZ?3_g6FQOSfwg ze(7;QRImulB#U``3ACiz1*sS@Kp;>(#T~+yo~>ZIJH!m?swpxHnJ4g|Ih6yj9ZBQy z$3JP5=C$fQagaA&bPPZ1(_(NHKHy4|9RS|+NVOfXUvJ?*Kj=or`WlDGB*`!-cfhEE z({*9;!gOuDvd7Gz({^97;GceG*JtHfHipG9cD{A!<#!F%?YLUiYwWFe(L2bm@~r5m zf)s>sHs5(?HD>Iz%79HN_7r#aM-~$1;uqQ0rN5VDJ}X-zIyRd?lj?pll5QfUWCivE zHY{zl?ZfvioSlk&f=hU(_5pkZ2d#OKD;Oi~AsG>qr2_5_^+h}OMj@V2L(qDltps{)E`f46=6BeL&Q|hFPJr@kg3YQv zWtdyUmIJXIw0gqm`Z1>qw9PsQi$EQ(>!3mJ+T0GMcRP1pQIWUHeyTkUhPHEmcbqx( bd%t9=E32aHb+2=Jd!7FQathy%Ycc=;>RLAL From f98f3e43b59dcf413cde0560306bd7e21ede9439 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:56:37 -0600 Subject: [PATCH 04/14] refactor: replace got with node-fetch --- .../frameworks/framework-detection.test.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index 688db23c8ab..31eae2078bb 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,9 +1,9 @@ import execa from 'execa' +import fetch from 'node-fetch' import { describe, test } from 'vitest' import cliPath from '../utils/cli-path.cjs' import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' -import got from '../utils/got.cjs' import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' import { withSiteBuilder } from '../utils/site-builder.cjs' import { normalize } from '../utils/snapshots.cjs' @@ -21,7 +21,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -39,7 +39,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -58,7 +58,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -78,7 +78,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -99,7 +99,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -277,7 +277,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -372,7 +372,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, context: null, debug: true, serve: true }, async ({ output, url }) => { - const response = await got(`${url}/hello`).json() + const response = await fetch(`${url}/hello`).then((res) => res.json()) t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() From 10afd4b593a46f33ef31a2cac101ddaf42b095a3 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 15:00:02 -0600 Subject: [PATCH 05/14] style: apply lint rules --- .../frameworks/framework-detection.test.mjs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index 31eae2078bb..c51f6728024 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -117,7 +117,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -128,7 +128,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -137,7 +137,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withSiteBuilder('site-with-unknown-framework', async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -151,7 +151,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -164,7 +164,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -177,7 +177,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -190,7 +190,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -213,7 +213,7 @@ describe.concurrent('frameworks/framework-detection', () => { }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -244,7 +244,7 @@ describe.concurrent('frameworks/framework-detection', () => { await childProcess } - const error = await asyncErrorBlock().catch((error) => error) + const error = await asyncErrorBlock().catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -258,7 +258,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -297,7 +297,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true Gatsby project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -307,7 +307,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -325,7 +325,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -348,7 +348,7 @@ describe.concurrent('frameworks/framework-detection', () => { name: 'frameworker', plugin: { onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require + // eslint-disable-next-line n/global-require, no-undef const { mkdir, writeFile } = require('fs').promises const generatedFunctionsDir = 'new_functions' From 691e1724ed546ad9b6224afda7d4287714349a61 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:07:49 -0600 Subject: [PATCH 06/14] refactor: move and rename test file --- .../framework-detection.test.cjs} | 12 ++++++------ .../snapshots/framework-detection.test.cjs.md} | 4 ++-- .../snapshots/framework-detection.test.cjs.snap} | Bin 3 files changed, 8 insertions(+), 8 deletions(-) rename tests/integration/{600.framework-detection.test.cjs => frameworks/framework-detection.test.cjs} (97%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.md => frameworks/snapshots/framework-detection.test.cjs.md} (98%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.snap => frameworks/snapshots/framework-detection.test.cjs.snap} (100%) diff --git a/tests/integration/600.framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.cjs similarity index 97% rename from tests/integration/600.framework-detection.test.cjs rename to tests/integration/frameworks/framework-detection.test.cjs index c0def572de7..85f093007c8 100644 --- a/tests/integration/600.framework-detection.test.cjs +++ b/tests/integration/frameworks/framework-detection.test.cjs @@ -3,12 +3,12 @@ const avaTest = require('ava') const { isCI } = require('ci-info') const execa = require('execa') -const cliPath = require('./utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('./utils/dev-server.cjs') -const got = require('./utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('./utils/handle-questions.cjs') -const { withSiteBuilder } = require('./utils/site-builder.cjs') -const { normalize } = require('./utils/snapshots.cjs') +const cliPath = require('../utils/cli-path.cjs') +const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') +const got = require('../utils/got.cjs') +const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') +const { withSiteBuilder } = require('../utils/site-builder.cjs') +const { normalize } = require('../utils/snapshots.cjs') const content = 'Hello World!' diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md similarity index 98% rename from tests/integration/snapshots/600.framework-detection.test.cjs.md rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.md index e87bc042ebe..fa31a47c6b1 100644 --- a/tests/integration/snapshots/600.framework-detection.test.cjs.md +++ b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `tests/integration/600.framework-detection.test.cjs` +# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` -The actual snapshot is saved in `600.framework-detection.test.cjs.snap`. +The actual snapshot is saved in `framework-detection.test.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap similarity index 100% rename from tests/integration/snapshots/600.framework-detection.test.cjs.snap rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap From dadc0e09a14238d892ce3cc00ba6a6292cdfe9a2 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:14:43 -0600 Subject: [PATCH 07/14] refactor: convert file to esm - convert file to esm - adjust file accordingly - update snapshots --- ....test.cjs => framework-detection.test.mjs} | 20 +++++++++--------- ...cjs.md => framework-detection.test.mjs.md} | 4 ++-- ...snap => framework-detection.test.mjs.snap} | Bin 3 files changed, 12 insertions(+), 12 deletions(-) rename tests/integration/frameworks/{framework-detection.test.cjs => framework-detection.test.mjs} (96%) rename tests/integration/frameworks/snapshots/{framework-detection.test.cjs.md => framework-detection.test.mjs.md} (99%) rename tests/integration/frameworks/snapshots/{framework-detection.test.cjs.snap => framework-detection.test.mjs.snap} (100%) diff --git a/tests/integration/frameworks/framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.mjs similarity index 96% rename from tests/integration/frameworks/framework-detection.test.cjs rename to tests/integration/frameworks/framework-detection.test.mjs index 85f093007c8..b8715ddff5a 100644 --- a/tests/integration/frameworks/framework-detection.test.cjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,14 +1,14 @@ // eslint-disable-next-line ava/use-test -const avaTest = require('ava') -const { isCI } = require('ci-info') -const execa = require('execa') - -const cliPath = require('../utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') -const got = require('../utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') -const { withSiteBuilder } = require('../utils/site-builder.cjs') -const { normalize } = require('../utils/snapshots.cjs') +import avaTest from 'ava' +import { isCI } from 'ci-info' +import execa from 'execa' + +import cliPath from '../utils/cli-path.cjs' +import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' +import got from '../utils/got.cjs' +import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' +import { withSiteBuilder } from '../utils/site-builder.cjs' +import { normalize } from '../utils/snapshots.cjs' const content = 'Hello World!' diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md similarity index 99% rename from tests/integration/frameworks/snapshots/framework-detection.test.cjs.md rename to tests/integration/frameworks/snapshots/framework-detection.test.mjs.md index fa31a47c6b1..17eb3e769d5 100644 --- a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md +++ b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` +# Snapshot report for `tests/integration/frameworks/framework-detection.test.mjs` -The actual snapshot is saved in `framework-detection.test.cjs.snap`. +The actual snapshot is saved in `framework-detection.test.mjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap similarity index 100% rename from tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap rename to tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap From 1b746f77eed54f72f80707da163e7d1b1b19fb77 Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:48:49 -0600 Subject: [PATCH 08/14] refactor: replace ava with vitest - replace ava with vitest - run test concurrently - update snapshots --- .../framework-detection.test.mjs.snap | 320 +++++++++ .../frameworks/framework-detection.test.mjs | 630 ++++++++++-------- .../snapshots/framework-detection.test.mjs.md | 303 --------- .../framework-detection.test.mjs.snap | Bin 2065 -> 0 bytes 4 files changed, 682 insertions(+), 571 deletions(-) create mode 100644 tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.mjs.md delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap diff --git a/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap new file mode 100644 index 00000000000..17a704491d1 --- /dev/null +++ b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap @@ -0,0 +1,320 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`frameworks/framework-detection > should default to process.cwd() and static server 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should detect a known framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App + +> start +> react-scripts start + +◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should filter frameworks with no dev command 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-gulp\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should force a specific framework when configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App +◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists" +`; + +exports[`frameworks/framework-detection > should log the command if using static server and \`command\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should not run framework detection if command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should pass framework-info env to framework sub process 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Nuxt 3 + +> dev +> node -p process.env.NODE_VERSION + +18 +◈ \\"npm run dev\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should print specific error when command doesn't exist 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists" +`; + +exports[`frameworks/framework-detection > should run \`command\` when both \`command\` and \`targetPort\` are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should run and serve a production build when using the \`serve\` command 1`] = ` +"◈ Injected netlify.toml file env var: CONTEXT_CHECK +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Running static server from \\"site-with-framework/public\\" +◈ Building site for production +◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again +​ +Netlify Build +──────────────────────────────────────────────────────────────── +​ +> Version + @netlify/build 0.0.0 +​ +> Flags + configPath:/file/path + edgeFunctionsBootstrapURL: https://650bfd807b21ed888883e25c--edge.netlify.com/bootstrap/index-combined.ts + offline: true + outputConfigPath:/file/path +​ +> Current directory + /file/path +​ +> Config file + /file/path +​ +> Context + production +​ +> Loading plugins + -/file/path from netlify.toml +​ +/file/path (onPreBuild event) +──────────────────────────────────────────────────────────────── +​ +Netlify configuration property \\"redirects\\" value changed to [ { from: /file/path', to: /file/path' } ]. +​ +/file/path onPreBuild completed in Xms) +​ +Functions bundling +──────────────────────────────────────────────────────────────── +​ +Packaging Functions from new_functions directory: + - hello.js +​ +​ +(Functions bundling completed in Xms) +​ +Save deploy artifacts +──────────────────────────────────────────────────────────────── +​ +​ +(Save deploy artifacts completed in Xms) +​ +Netlify Build Complete +──────────────────────────────────────────────────────────────── +​ +(Netlify Build completed in Xms) + +◈ Static server listening to 88888 +◈ Loaded function hello + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should run and serve a production build when using the \`serve\` command 2`] = ` +"◈ Injected netlify.toml file env var: CONTEXT_CHECK +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Running static server from \\"site-with-framework/public\\" +◈ Building site for production +◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again +​ +Netlify Build +──────────────────────────────────────────────────────────────── +​ +> Version + @netlify/build 0.0.0 +​ +> Flags + configPath:/file/path + edgeFunctionsBootstrapURL: https://650bfd807b21ed888883e25c--edge.netlify.com/bootstrap/index-combined.ts + offline: true + outputConfigPath:/file/path +​ +> Current directory + /file/path +​ +> Config file + /file/path +​ +> Context + production +​ +> Loading plugins + -/file/path from netlify.toml +​ +/file/path (onPreBuild event) +──────────────────────────────────────────────────────────────── +​ +Netlify configuration property \\"redirects\\" value changed to [ { from: /file/path', to: /file/path' } ]. +​ +/file/path onPreBuild completed in Xms) +​ +Functions bundling +──────────────────────────────────────────────────────────────── +​ +Packaging Functions from new_functions directory: + - hello.js +​ +​ +(Functions bundling completed in Xms) +​ +Save deploy artifacts +──────────────────────────────────────────────────────────────── +​ +​ +(Save deploy artifacts completed in Xms) +​ +Netlify Build Complete +──────────────────────────────────────────────────────────────── +​ +(Netlify Build completed in Xms) + +◈ Static server listening to 88888 +◈ Loaded function hello + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should start custom command if framework=#custom, command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but command is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but targetPort is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw when forcing a non supported framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Invalid framework \\"to-infinity-and-beyond-js\\". It should be one of: *" +`; + +exports[`frameworks/framework-detection > should use static server when --dir flag is passed 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should use static server when framework is set to #static 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should warn if using static server and \`targetPort\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Ignoring 'targetPort' setting since using a simple static server. +◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index b8715ddff5a..657c5e41576 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,7 +1,5 @@ -// eslint-disable-next-line ava/use-test -import avaTest from 'ava' -import { isCI } from 'ci-info' import execa from 'execa' +import { describe, test } from 'vitest' import cliPath from '../utils/cli-path.cjs' import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' @@ -12,197 +10,196 @@ import { normalize } from '../utils/snapshots.cjs' const content = 'Hello World!' -const test = isCI ? avaTest.serial.bind(avaTest) : avaTest +describe.concurrent('frameworks/framework-detection', () => { + test('should default to process.cwd() and static server', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) -test('should default to process.cwd() and static server', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) }) }) -}) -test('should use static server when --dir flag is passed', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - - await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should use static server when --dir flag is passed', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) + await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) -test('should use static server when framework is set to #static', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .withNetlifyToml({ config: { dev: { framework: '#static' } } }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) }) }) -}) -test('should log the command if using static server and `command` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, - async ({ output, url }) => { + test('should use static server when framework is set to #static', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withNetlifyToml({ config: { dev: { framework: '#static' } } }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) - }) -}) + t.expect(response).toEqual(content) -test('should warn if using static server and `targetPort` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .buildAsync() + }) + }) - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, - async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should log the command if using static server and `command` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) + }) - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) + test('should warn if using static server and `targetPort` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) }) -}) -test('should run `command` when both `command` and `targetPort` are configured', async (t) => { - await withSiteBuilder('empty-site', async (builder) => { - await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() + test('should run `command` when both `command` and `targetPort` are configured', async (t) => { + await withSiteBuilder('empty-site', async (builder) => { + await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() - // a failure is expected since we use `echo hello` instead of starting a server - const error = await t.throwsAsync(() => - withDevServer( + // a failure is expected since we use `echo hello` instead of starting a server + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should force a specific framework when configured', async (t) => { - await withSiteBuilder('site-with-mocked-cra', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() + test('should force a specific framework when configured', async (t) => { + await withSiteBuilder('site-with-mocked-cra', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw when forcing a non supported framework', async (t) => { - await withSiteBuilder('site-with-unknown-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() + test('should throw when forcing a non supported framework', async (t) => { + await withSiteBuilder('site-with-unknown-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should detect a known framework', async (t) => { - await withSiteBuilder('site-with-cra', async (builder) => { - await builder - .withPackageJson({ - packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, - }) - .buildAsync() - - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + test('should detect a known framework', async (t) => { + await withSiteBuilder('site-with-cra', async (builder) => { + await builder + .withPackageJson({ + packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, + }) + .buildAsync() + + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw if framework=#custom but command is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + test('should throw if framework=#custom but command is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer( + { cwd: builder.directory, args: ['--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should throw if framework=#custom but targetPort is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + test('should throw if framework=#custom but targetPort is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() + test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() - const error = await t.throwsAsync(() => - withDevServer( + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test(`should print specific error when command doesn't exist`, async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.buildAsync() + test(`should print specific error when command doesn't exist`, async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.buildAsync() - const error = await t.throwsAsync(() => - withDevServer( + const error = await withDevServer( { cwd: builder.directory, args: [ @@ -216,153 +213,250 @@ test(`should print specific error when command doesn't exist`, async (t) => { }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should prompt when multiple frameworks are detected', async (t) => { - await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, - scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, - }, - }) - .withContentFile({ path: 'gatsby-config.js', content: '' }) - .buildAsync() + ).catch((error) => error) - // a failure is expected since this is not a true framework project - const error = await t.throwsAsync(async () => { - const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) - handleQuestions(childProcess, [ - { - question: 'Multiple possible dev commands found', - answer: answerWithValue(DOWN), - }, - ]) + test('should prompt when multiple frameworks are detected', async (t) => { + await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, + scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, + }, + }) + .withContentFile({ path: 'gatsby-config.js', content: '' }) + .buildAsync() + + // a failure is expected since this is not a true framework project + const asyncErrorBlock = async () => { + const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) + + handleQuestions(childProcess, [ + { + question: 'Multiple possible start commands found', + answer: answerWithValue(DOWN), + }, + ]) - await childProcess + await childProcess + } + const error = await asyncErrorBlock().catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) }) -}) -test('should not run framework detection if command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-hugo-config', async (builder) => { - await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() + test('should not run framework detection if command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-hugo-config', async (builder) => { + await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() - // a failure is expected since the command exits early - const error = await t.throwsAsync(() => - withDevServer( + // a failure is expected since the command exits early + const error = await withDevServer( { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) }) -}) -test('should filter frameworks with no dev command', async (t) => { - await withSiteBuilder('site-with-gulp', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, - }) - .withPackageJson({ - packageJson: { dependencies: { gulp: '1.0.0' } }, + test('should filter frameworks with no dev command', async (t) => { + await withSiteBuilder('site-with-gulp', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withPackageJson({ + packageJson: { dependencies: { gulp: '1.0.0' } }, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }) - .buildAsync() + }) + }) - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) + test('should pass framework-info env to framework sub process', async (t) => { + await withSiteBuilder('site-with-gatsby', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { nuxt3: '^2.0.0' }, + scripts: { dev: 'node -p process.env.NODE_VERSION' }, + }, + }) + .buildAsync() - t.snapshot(normalize(output, { duration: true, filePath: true })) + // a failure is expected since this is not a true Gatsby project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) -}) -test('should start static service for frameworks without port, forced framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() + test('should start static service for frameworks without port, forced framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) }) -}) -test('should start static service for frameworks without port, detected framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, - scripts: {}, - }, - }) - .withContentFile({ path: 'remix.config.js', content: '' }) - .buildAsync() + test('should start static service for frameworks without port, detected framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, + scripts: {}, + }, + }) + .withContentFile({ path: 'remix.config.js', content: '' }) + .buildAsync() - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) }) -}) -test('should run and serve a production build when using the `serve` command', async (t) => { - await withSiteBuilder('site-with-framework', async (builder) => { - await builder - .withNetlifyToml({ - config: { - build: { publish: 'public' }, - context: { - dev: { environment: { CONTEXT_CHECK: 'DEV' } }, - production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + test('should run and serve a production build when using the `serve` command', async (t) => { + await withSiteBuilder('site-with-framework', async (builder) => { + await builder + .withNetlifyToml({ + config: { + build: { publish: 'public' }, + context: { + dev: { environment: { CONTEXT_CHECK: 'DEV' } }, + production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + }, + functions: { directory: 'functions' }, + plugins: [{ package: './plugins/frameworker' }], }, - functions: { directory: 'functions' }, - plugins: [{ package: './plugins/frameworker' }], - }, - }) - .withBuildPlugin({ - name: 'frameworker', - plugin: { - onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require - const { mkdir, writeFile } = require('fs').promises - - const generatedFunctionsDir = 'new_functions' - netlifyConfig.functions.directory = generatedFunctionsDir - - netlifyConfig.redirects.push({ - from: '/hello', - to: '/.netlify/functions/hello', - }) - - await mkdir(generatedFunctionsDir) - await writeFile( - `${generatedFunctionsDir}/hello.js`, - `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, - ) + }) + .withBuildPlugin({ + name: 'frameworker', + plugin: { + onPreBuild: async ({ netlifyConfig }) => { + // eslint-disable-next-line n/global-require + const { mkdir, writeFile } = require('fs').promises + + const generatedFunctionsDir = 'new_functions' + netlifyConfig.functions.directory = generatedFunctionsDir + + netlifyConfig.redirects.push({ + from: '/hello', + to: '/.netlify/functions/hello', + }) + + await mkdir(generatedFunctionsDir) + await writeFile( + `${generatedFunctionsDir}/hello.js`, + `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, + ) + }, }, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, context: null, debug: true, serve: true }, + async ({ output, url }) => { + const response = await got(`${url}/hello`).json() + t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() }, - }) - .buildAsync() + ) + }) + }) + + test('should start static service for frameworks without port, forced framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() + + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) + }) + + test('should start static service for frameworks without port, detected framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, + scripts: {}, + }, + }) + .withContentFile({ path: 'remix.config.js', content: '' }) + .buildAsync() + + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) + }) + + test('should run and serve a production build when using the `serve` command', async (t) => { + await withSiteBuilder('site-with-framework', async (builder) => { + await builder + .withNetlifyToml({ + config: { + build: { publish: 'public' }, + context: { + dev: { environment: { CONTEXT_CHECK: 'DEV' } }, + production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + }, + functions: { directory: 'functions' }, + plugins: [{ package: './plugins/frameworker' }], + }, + }) + .withBuildPlugin({ + name: 'frameworker', + plugin: { + onPreBuild: async ({ netlifyConfig }) => { + // eslint-disable-next-line n/global-require + const { mkdir, writeFile } = require('fs').promises + + const generatedFunctionsDir = 'new_functions' + netlifyConfig.functions.directory = generatedFunctionsDir + + netlifyConfig.redirects.push({ + from: '/hello', + to: '/.netlify/functions/hello', + }) + + await mkdir(generatedFunctionsDir) + await writeFile( + `${generatedFunctionsDir}/hello.js`, + `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, + ) + }, + }, + }) + .buildAsync() - await withDevServer( - { cwd: builder.directory, context: null, debug: true, serve: true }, - async ({ output, url }) => { - const response = await got(`${url}/hello`).json() - t.deepEqual(response, { CONTEXT_CHECK: 'PRODUCTION' }) + await withDevServer( + { cwd: builder.directory, context: null, debug: true, serve: true }, + async ({ output, url }) => { + const response = await got(`${url}/hello`).json() + t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) }) }) diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md deleted file mode 100644 index 17eb3e769d5..00000000000 --- a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.md +++ /dev/null @@ -1,303 +0,0 @@ -# Snapshot report for `tests/integration/frameworks/framework-detection.test.mjs` - -The actual snapshot is saved in `framework-detection.test.mjs.snap`. - -Generated by [AVA](https://avajs.dev). - -## should default to process.cwd() and static server - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when --dir flag is passed - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when framework is set to #static - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should log the command if using static server and `command` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should warn if using static server and `targetPort` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Ignoring 'targetPort' setting since using a simple static server.␊ - ◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should run `command` when both `command` and `targetPort` are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should force a specific framework when configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists` - -## should throw when forcing a non supported framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Invalid framework "to-infinity-and-beyond-js". It should be one of: *` - -## should detect a known framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should throw if framework=#custom but command is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should throw if framework=#custom but targetPort is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should start custom command if framework=#custom, command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should print specific error when command doesn't exist - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - ◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists` - -## should prompt when multiple frameworks are detected - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ? Multiple possible dev commands found (Use arrow keys or type to search)␊ - > [Gatsby] 'npm run develop' ␊ - [Create React App] 'npm run start' ? Multiple possible dev commands found ␊ - [Gatsby] 'npm run develop' ␊ - > [Create React App] 'npm run start' ? Multiple possible dev commands found Create React App-npm run start␊ - ␊ - Update your netlify.toml to avoid this selection prompt next time:␊ - ␊ - [build]␊ - command = "react-scripts build"␊ - publish = "build"␊ - ␊ - [dev]␊ - command = "npm run start"␊ - ␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should not run framework detection if command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should filter frameworks with no dev command - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-gulp"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should run and serve a production build when using the `serve` command - -> Snapshot 1 - - `◈ Injected netlify.toml file env var: CONTEXT_CHECK␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Running static server from "site-with-framework/public"␊ - ◈ Building site for production␊ - ◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again␊ - ​␊ - Netlify Build ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - > Version␊ - @netlify/build 0.0.0␊ - ​␊ - > Flags␊ - configPath:/file/path␊ - offline: true␊ - outputConfigPath:/file/path␊ - ​␊ - > Current directory␊ - /file/path␊ - ​␊ - > Config file␊ - /file/path␊ - ​␊ - > Context␊ - production␊ - ​␊ - > Loading plugins␊ - -/file/path from netlify.toml␊ - ​␊ - /file/path (onPreBuild event) ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Netlify configuration property "redirects" value changed to [ { from: /file/path', to: /file/path' } ].␊ - ​␊ - /file/path onPreBuild completed in Xms)␊ - ​␊ - Functions bundling ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Packaging Functions from new_functions directory:␊ - - hello.js␊ - ​␊ - ​␊ - (Functions bundling completed in Xms)␊ - ​␊ - Save deploy artifacts ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - ​␊ - (Save deploy artifacts completed in Xms)␊ - ​␊ - Netlify Build Complete ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - (Netlify Build completed in Xms)␊ - ␊ - ◈ Static server listening to 88888␊ - ◈ Loaded function hello␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.mjs.snap deleted file mode 100644 index e604422a50f62b6be41f7759b11163a75d542119..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2065 zcmV+s2=4bmRzVyL_Bg6gf z$GAHjl^=@;00000000B+T0xH+w-xrNaG!mQ<5WD2m+)93KU2V31FbTCik3jDo~(BPC2!ww8sKQ+hhMi`yR=W zW>(T>?ReuPD|uzDMDp?RS1R)aO<|Mm4{4Tj4XKi&%4%FH#f5>1RQvQk$rR2i)zq54&P`bW1L3@F8#&6Y z5tw9Vhz-4jkN41cY%(eAJOz(wT~k@o62{ePG&ctA>$bPcA(62LW;!r5rqG?8ojA|h z)kLuz?fBm#v~m_fzm1bb4iucrnt8nx!a`HW#4Zn7Ix{>XFQZH({7yt(x2i>vD}XD* z&1N~d$#YqZ2nUa=>)0@xXWDQ(9WL`3dISLg+`Ie1y}R#yD}O$8{{05-`+P6OlD()}(oO zq`7c7X;Q^ToN^Iy26G05%~{uPNn-tXgFAm;nOKj)9m-_w+4Os%BarhT^e%+!e7nxK zYw37I(s9*GM=miWh8!?vM^t`iDXPh0SW?q1-{%&|Ni0R04NA36!)q>`bS_=;T$(T? z4keIbYQW8|ROTx=bmq4W4voK7IzF63R|i5WG7`@H3#*)mmPO3{lGxID+TIV2Rk~|% zK|*#wDw}582OIW?JTm~S1T~#6u+y62Yl?q6DE_jixGF_0585ibFR_@Mf3`q$rubn@ zzxjEC=%1ZhMf9VDvX5kCJJyZZiZ?Db*1+DGV94`a+7T@t4<*?5E#P;MQ;8oS6Aq8J z;rg(2b0=~l8g|{h2QTYg;aAD%;^gM}={LGAeVE(dl7EF-PO-ySXKYpzTJ?{AB4N=;!c@%5Wi3dMJ2kr@Z$V zAF{;o+@b>tQzT^je5&bSVx|Rm!NgQN+{TpAdx;s{pYB0er2xMLAz-E2JD6>1{j8jX zu-SX^(q`}c)0a1UPoMANyBF|zZL{~prRM8PNA#LzJ;bMr_vzF53lG7kgEK~r`8In` zUARpDb%WqWkx)-do(AU-bT*b5Wfm*dxo4aY7s2nKcxNNt34&g~%<^O}sAT3jXf+eN zZEpouBJ_~j{U?ECbA4dL(N^$%tU<1M;t6T&@OcF|(;CWh50=v2+BlHY)*^lkB7W@0 zv~$%lEz6C)N}0*AH78`9^-EOwi$)Oqas4M4-|SaHgEBAHw_EGmt%rBJb)|N@W&Z}t zl8aF~PD)1wn^RpK=k9{(#`c!&cx$y({OHFGsraA2oVaa;U68^^F&A zzVUYV38SVU1_%VYr?^Ad>Wno^ts_hYt}LK!q3sDhXwGFkBUAMq+;6~_F2b8!Y1#*X=RHz84%nZy@t^N>C1(STU0jOYWoFpfabF$aulTu4(;Tx- z2aGB?y)R8sn(orx&SKZ6oq4)}#Xfet4fN%$2FqTYtsYIb=@pC`ink&!2bmzpA)1eO zQCsJd9aihGCB?4dE-o-Z2($ftj)95?RUON!lLcKJP3iRDHc7WoYVr~bUQ1WY!XCV1 z;q27*Cp?EOjSt{m*lQmIxrQ;yA&L|!93HK2j`X(ed!-b1Q|ZJalAJd5#PM^N#rteP zOP{0R!*}v_I{RqGqD}yjt9aYDwY5OcttC({$NV}Q(-F4Fmmt72PhJ*9G^9EV%y Date: Thu, 3 Aug 2023 14:56:37 -0600 Subject: [PATCH 09/14] refactor: replace got with node-fetch --- .../frameworks/framework-detection.test.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index 657c5e41576..7189856288f 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,9 +1,9 @@ import execa from 'execa' +import fetch from 'node-fetch' import { describe, test } from 'vitest' import cliPath from '../utils/cli-path.cjs' import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' -import got from '../utils/got.cjs' import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' import { withSiteBuilder } from '../utils/site-builder.cjs' import { normalize } from '../utils/snapshots.cjs' @@ -21,7 +21,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -39,7 +39,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -58,7 +58,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -78,7 +78,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -99,7 +99,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -277,7 +277,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -372,7 +372,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, context: null, debug: true, serve: true }, async ({ output, url }) => { - const response = await got(`${url}/hello`).json() + const response = await fetch(`${url}/hello`).then((res) => res.json()) t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() From d6fc578ff43ae2e0fdd0c4a92419d88c1e170a5a Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 15:00:02 -0600 Subject: [PATCH 10/14] style: apply lint rules --- .../frameworks/framework-detection.test.mjs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index 7189856288f..b9af3beebe5 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -117,7 +117,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -128,7 +128,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -137,7 +137,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withSiteBuilder('site-with-unknown-framework', async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -151,7 +151,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -164,7 +164,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -177,7 +177,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -190,7 +190,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -213,7 +213,7 @@ describe.concurrent('frameworks/framework-detection', () => { }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -244,7 +244,7 @@ describe.concurrent('frameworks/framework-detection', () => { await childProcess } - const error = await asyncErrorBlock().catch((error) => error) + const error = await asyncErrorBlock().catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -258,7 +258,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -297,7 +297,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true Gatsby project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -307,7 +307,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -325,7 +325,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -348,7 +348,7 @@ describe.concurrent('frameworks/framework-detection', () => { name: 'frameworker', plugin: { onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require + // eslint-disable-next-line n/global-require, no-undef const { mkdir, writeFile } = require('fs').promises const generatedFunctionsDir = 'new_functions' From b9dc080a65382e7690d974357804f2805b681cff Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:07:49 -0600 Subject: [PATCH 11/14] refactor: move and rename test file --- .../framework-detection.test.cjs} | 12 ++++++------ .../snapshots/framework-detection.test.cjs.md} | 4 ++-- .../snapshots/framework-detection.test.cjs.snap} | Bin 3 files changed, 8 insertions(+), 8 deletions(-) rename tests/integration/{600.framework-detection.test.cjs => frameworks/framework-detection.test.cjs} (97%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.md => frameworks/snapshots/framework-detection.test.cjs.md} (98%) rename tests/integration/{snapshots/600.framework-detection.test.cjs.snap => frameworks/snapshots/framework-detection.test.cjs.snap} (100%) diff --git a/tests/integration/600.framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.cjs similarity index 97% rename from tests/integration/600.framework-detection.test.cjs rename to tests/integration/frameworks/framework-detection.test.cjs index 1cd20213b2b..238ec884731 100644 --- a/tests/integration/600.framework-detection.test.cjs +++ b/tests/integration/frameworks/framework-detection.test.cjs @@ -3,12 +3,12 @@ const avaTest = require('ava') const { isCI } = require('ci-info') const execa = require('execa') -const cliPath = require('./utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('./utils/dev-server.cjs') -const got = require('./utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('./utils/handle-questions.cjs') -const { withSiteBuilder } = require('./utils/site-builder.cjs') -const { normalize } = require('./utils/snapshots.cjs') +const cliPath = require('../utils/cli-path.cjs') +const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') +const got = require('../utils/got.cjs') +const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') +const { withSiteBuilder } = require('../utils/site-builder.cjs') +const { normalize } = require('../utils/snapshots.cjs') const content = 'Hello World!' diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md similarity index 98% rename from tests/integration/snapshots/600.framework-detection.test.cjs.md rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.md index f93f27bdc77..24db116bc64 100644 --- a/tests/integration/snapshots/600.framework-detection.test.cjs.md +++ b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md @@ -1,6 +1,6 @@ -# Snapshot report for `tests/integration/600.framework-detection.test.cjs` +# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` -The actual snapshot is saved in `600.framework-detection.test.cjs.snap`. +The actual snapshot is saved in `framework-detection.test.cjs.snap`. Generated by [AVA](https://avajs.dev). diff --git a/tests/integration/snapshots/600.framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap similarity index 100% rename from tests/integration/snapshots/600.framework-detection.test.cjs.snap rename to tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap From 1e19932c8d5b57a1a3c0687ee833d662f167ddba Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:14:43 -0600 Subject: [PATCH 12/14] refactor: convert file to esm - convert file to esm - adjust file accordingly - update snapshots --- .../framework-detection.test.mjs.snap | 350 ++++++++++++++++ .../frameworks/framework-detection.test.cjs | 365 ----------------- .../frameworks/framework-detection.test.mjs | 383 ++++++++++++++++++ .../snapshots/framework-detection.test.cjs.md | 302 -------------- .../framework-detection.test.cjs.snap | Bin 2053 -> 0 bytes 5 files changed, 733 insertions(+), 667 deletions(-) create mode 100644 tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap delete mode 100644 tests/integration/frameworks/framework-detection.test.cjs create mode 100644 tests/integration/frameworks/framework-detection.test.mjs delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.cjs.md delete mode 100644 tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap diff --git a/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap new file mode 100644 index 00000000000..7ec3e0e5361 --- /dev/null +++ b/tests/integration/frameworks/__snapshots__/framework-detection.test.mjs.snap @@ -0,0 +1,350 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`frameworks/framework-detection > should default to process.cwd() and static server 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should detect a known framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App + +> start +> react-scripts start + +◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should filter frameworks with no dev command 1`] = ` +"◈ Netlify Dev ◈ +◈ No app server detected. Using simple static server +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-gulp\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should force a specific framework when configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Create React App +◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists" +`; + +exports[`frameworks/framework-detection > should log the command if using static server and \`command\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should not run framework detection if command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should pass framework-info env to framework sub process 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with Nuxt 3 + +> dev +> node -p process.env.NODE_VERSION + +18 +◈ \\"npm run dev\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should print specific error when command doesn't exist 1`] = ` +"◈ Netlify Dev ◈ +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists" +`; + +exports[`frameworks/framework-detection > should run \`command\` when both \`command\` and \`targetPort\` are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with custom config +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should run and serve a production build when using the \`serve\` command 1`] = ` +"[project.ts]: detectFrameworks +[project.ts]: detectBuildSystem +[project.ts]: detectWorkspaces +[project.ts]: detectPackageManager +[project.ts]: detectFrameworksInPath - undefined +◈ Injected netlify.toml file env var: CONTEXT_CHECK +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Running static server from \\"site-with-framework/public\\" +◈ Building site for production +◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again +​ +Netlify Build +──────────────────────────────────────────────────────────────── +​ +> Version + @netlify/build 0.0.0 +​ +> Flags + configPath:/file/path + cwd:/file/path + debug: true + edgeFunctionsBootstrapURL: https://650bfd807b21ed888883e25c--edge.netlify.com/bootstrap/index-combined.ts + mode: cli + offline: true + outputConfigPath:/file/path + saveConfig: true +​ +> Current directory + /file/path +​ +> Config file + /file/path +​ +> Resolved config + build: + environment: + - CONTEXT_CHECK + publish:/file/path + publishOrigin: config + functionsDirectory:/file/path + plugins: + - inputs: {} + origin: config + package:/file/path +​ +> Context + production +​ +> Loading plugins + -/file/path from netlify.toml +​ +/file/path (onPreBuild event) +──────────────────────────────────────────────────────────────── +​ +Netlify configuration property \\"functions.directory\\" value changed to 'new_functions'. +Netlify configuration property \\"redirects\\" value changed to [ { from: /file/path', to: /file/path' } ]. +​ +> Updated config + build: + environment: + - CONTEXT_CHECK + publish:/file/path + publishOrigin: config + functionsDirectory:/file/path + plugins: + - inputs: {} + origin: config + package:/file/path + redirects: + - from:/file/path + to:/file/path + redirectsOrigin: inline +​ +/file/path onPreBuild completed in Xms) +Build step duration:/file/path onPreBuild completed in Xms +​ +Functions bundling +──────────────────────────────────────────────────────────────── +​ +Packaging Functions from new_functions directory: + - hello.js +​ +​ +(Functions bundling completed in Xms) +Build step duration: Functions bundling completed in Xms +​ +Save deploy artifacts +──────────────────────────────────────────────────────────────── +​ +​ +> Uploaded config + [build] + publish = \\"public\\" +​ + [context] +​ + [context.dev] +​ + [context.dev.environment] + CONTEXT_CHECK = \\"DEV\\" +​ + [context.production] +​ + [context.production.environment] + CONTEXT_CHECK = \\"PRODUCTION\\" +​ + [functions] + directory = \\"functions\\" +​ + [[plugins]] + package = /file/path\\" +​ +> Uploaded headers + No headers +​ +> Uploaded redirects + No redirects +​ +​ +(Save deploy artifacts completed in Xms) +Build step duration: Save deploy artifacts completed in Xms +​ +Netlify Build Complete +──────────────────────────────────────────────────────────────── +​ +(Netlify Build completed in Xms) +Build step duration: Netlify Build completed in Xms + +◈ Static server listening to 88888 +◈ Extracted function hello from/file/path +◈ Functions server is listening on 88888 +getBinaryVersion failed Error: Command failed with ENOENT: deno --version +spawn deno ENOENT + at ChildProcess._handle.onexit (node:internal/child_process:283:19) + at onErrorNT (node:internal/child_process:476:16) + at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { + errno: -2, + code: 'ENOENT', + syscall: 'spawn deno', + path: 'deno', + spawnargs: [ '--version' ], + originalMessage: 'spawn deno ENOENT', + shortMessage: 'Command failed with ENOENT: deno --version/nspawn deno ENOENT', + command: 'deno --version', + escapedCommand: 'deno --version', + exitCode: undefined, + signal: undefined, + signalDescription: undefined, + stdout: '', + stderr: '', + failed: true, + timedOut: false, + isCanceled: false, + killed: false +} +No globalVersion or semver not satisfied. globalVersion: undefined, versionRange: ^1.32.5 +Using cached Deno CLI from/file/path + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should start custom command if framework=#custom, command and targetPort are configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Setting up local development server +◈ Starting Netlify Dev with #custom +hello +◈ \\"echo hello\\" exited with code *. Shutting down Netlify Dev server" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but command is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw if framework=#custom but targetPort is missing 1`] = ` +"◈ Netlify Dev ◈ +◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'" +`; + +exports[`frameworks/framework-detection > should throw when forcing a non supported framework 1`] = ` +"◈ Netlify Dev ◈ +◈ Invalid framework \\"to-infinity-and-beyond-js\\". It should be one of: *" +`; + +exports[`frameworks/framework-detection > should use static server when --dir flag is passed 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should use static server when framework is set to #static 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '[dev.framework]' was set to '#static' +◈ Unable to determine public folder to serve files from. Using current working directory +◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings. +◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection +◈ Running static server from \\"site-with-index-file\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; + +exports[`frameworks/framework-detection > should warn if using static server and \`targetPort\` is configured 1`] = ` +"◈ Netlify Dev ◈ +◈ Using simple static server because '--dir' flag was specified +◈ Ignoring 'targetPort' setting since using a simple static server. +◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port +◈ Running static server from \\"site-with-index-file/public\\" +◈ Setting up local development server + +◈ Static server listening to 88888 + + ┌──────────────────────────────────────────────────┐ + │ │ + │ ◈ Server now ready on http://localhost:88888 │ + │ │ + └──────────────────────────────────────────────────┘" +`; diff --git a/tests/integration/frameworks/framework-detection.test.cjs b/tests/integration/frameworks/framework-detection.test.cjs deleted file mode 100644 index 238ec884731..00000000000 --- a/tests/integration/frameworks/framework-detection.test.cjs +++ /dev/null @@ -1,365 +0,0 @@ -// eslint-disable-next-line ava/use-test -const avaTest = require('ava') -const { isCI } = require('ci-info') -const execa = require('execa') - -const cliPath = require('../utils/cli-path.cjs') -const { getExecaOptions, withDevServer } = require('../utils/dev-server.cjs') -const got = require('../utils/got.cjs') -const { DOWN, answerWithValue, handleQuestions } = require('../utils/handle-questions.cjs') -const { withSiteBuilder } = require('../utils/site-builder.cjs') -const { normalize } = require('../utils/snapshots.cjs') - -const content = 'Hello World!' - -const test = isCI ? avaTest.serial.bind(avaTest) : avaTest - -test('should default to process.cwd() and static server', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, - }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) - -test('should use static server when --dir flag is passed', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - - await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) - -test('should use static server when framework is set to #static', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, - }) - .withNetlifyToml({ config: { dev: { framework: '#static' } } }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) - -test('should log the command if using static server and `command` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, - async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) - }) -}) - -test('should warn if using static server and `targetPort` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { - await builder - .withContentFile({ - path: 'public/index.html', - content, - }) - .buildAsync() - - await withDevServer( - { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, - async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }, - ) - }) -}) - -test('should run `command` when both `command` and `targetPort` are configured', async (t) => { - await withSiteBuilder('empty-site', async (builder) => { - await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() - - // a failure is expected since we use `echo hello` instead of starting a server - const error = await t.throwsAsync(() => - withDevServer( - { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, - () => {}, - true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should force a specific framework when configured', async (t) => { - await withSiteBuilder('site-with-mocked-cra', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() - - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should throw when forcing a non supported framework', async (t) => { - await withSiteBuilder('site-with-unknown-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should detect a known framework', async (t) => { - await withSiteBuilder('site-with-cra', async (builder) => { - await builder - .withPackageJson({ - packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, - }) - .buildAsync() - - // a failure is expected since this is not a true create-react-app project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should throw if framework=#custom but command is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should throw if framework=#custom but targetPort is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() - - const error = await t.throwsAsync(() => - withDevServer({ cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() - - const error = await t.throwsAsync(() => - withDevServer( - { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, - () => {}, - true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test(`should print specific error when command doesn't exist`, async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { - await builder.buildAsync() - - const error = await t.throwsAsync(() => - withDevServer( - { - cwd: builder.directory, - args: [ - '--command', - 'oops-i-did-it-again forgot-to-use-a-valid-command', - '--target-port', - '3000', - '--framework', - '#custom', - ], - }, - () => {}, - true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should prompt when multiple frameworks are detected', async (t) => { - await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, - scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, - }, - }) - .withContentFile({ path: 'gatsby-config.js', content: '' }) - .buildAsync() - - // a failure is expected since this is not a true framework project - const error = await t.throwsAsync(async () => { - const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) - - handleQuestions(childProcess, [ - { - question: 'Multiple possible dev commands found', - answer: answerWithValue(DOWN), - }, - ]) - - await childProcess - }) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should not run framework detection if command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-hugo-config', async (builder) => { - await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() - - // a failure is expected since the command exits early - const error = await t.throwsAsync(() => - withDevServer( - { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, - () => {}, - true, - ), - ) - t.snapshot(normalize(error.stdout, { duration: true, filePath: true })) - }) -}) - -test('should filter frameworks with no dev command', async (t) => { - await withSiteBuilder('site-with-gulp', async (builder) => { - await builder - .withContentFile({ - path: 'index.html', - content, - }) - .withPackageJson({ - packageJson: { dependencies: { gulp: '1.0.0' } }, - }) - .buildAsync() - - await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() - t.is(response, content) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) - -test('should start static service for frameworks without port, forced framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() - - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) - }) -}) - -test('should start static service for frameworks without port, detected framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { - await builder - .withPackageJson({ - packageJson: { - dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, - scripts: {}, - }, - }) - .withContentFile({ path: 'remix.config.js', content: '' }) - .buildAsync() - - // a failure is expected since this is not a true remix project - const error = await t.throwsAsync(() => withDevServer({ cwd: builder.directory }, () => {}, true)) - t.true(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)) - }) -}) - -test('should run and serve a production build when using the `serve` command', async (t) => { - await withSiteBuilder('site-with-framework', async (builder) => { - await builder - .withNetlifyToml({ - config: { - build: { publish: 'public' }, - context: { - dev: { environment: { CONTEXT_CHECK: 'DEV' } }, - production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, - }, - functions: { directory: 'functions' }, - plugins: [{ package: './plugins/frameworker' }], - }, - }) - .withBuildPlugin({ - name: 'frameworker', - plugin: { - onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require - const { mkdir, writeFile } = require('fs').promises - - const generatedFunctionsDir = 'new_functions' - netlifyConfig.functions.directory = generatedFunctionsDir - - netlifyConfig.redirects.push({ - from: '/hello', - to: '/.netlify/functions/hello', - }) - - await mkdir(generatedFunctionsDir) - await writeFile( - `${generatedFunctionsDir}/hello.js`, - `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, - ) - }, - }, - }) - .buildAsync() - - await withDevServer({ cwd: builder.directory, context: null, serve: true }, async ({ output, url }) => { - const response = await got(`${url}/hello`).json() - t.deepEqual(response, { CONTEXT_CHECK: 'PRODUCTION' }) - - t.snapshot(normalize(output, { duration: true, filePath: true })) - }) - }) -}) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs new file mode 100644 index 00000000000..c0c30004353 --- /dev/null +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -0,0 +1,383 @@ +import execa from 'execa' +import { describe, test } from 'vitest' + +import cliPath from '../utils/cli-path.cjs' +import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' +import got from '../utils/got.cjs' +import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' +import { withSiteBuilder } from '../utils/site-builder.cjs' +import { normalize } from '../utils/snapshots.cjs' + +const content = 'Hello World!' + +describe.concurrent('frameworks/framework-detection', () => { + test('should default to process.cwd() and static server', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + }) + + test('should use static server when --dir flag is passed', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + }) + + test('should use static server when framework is set to #static', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withNetlifyToml({ config: { dev: { framework: '#static' } } }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + }) + + test('should log the command if using static server and `command` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) + }) + + test('should warn if using static server and `targetPort` is configured', async (t) => { + await withSiteBuilder('site-with-index-file', async (builder) => { + await builder + .withContentFile({ + path: 'public/index.html', + content, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, + async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) + }) + + test('should run `command` when both `command` and `targetPort` are configured', async (t) => { + await withSiteBuilder('empty-site', async (builder) => { + await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() + + // a failure is expected since we use `echo hello` instead of starting a server + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should force a specific framework when configured', async (t) => { + await withSiteBuilder('site-with-mocked-cra', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() + + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should throw when forcing a non supported framework', async (t) => { + await withSiteBuilder('site-with-unknown-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() + + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should detect a known framework', async (t) => { + await withSiteBuilder('site-with-cra', async (builder) => { + await builder + .withPackageJson({ + packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, + }) + .buildAsync() + + // a failure is expected since this is not a true create-react-app project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should throw if framework=#custom but command is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + + const error = await withDevServer( + { cwd: builder.directory, args: ['--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should throw if framework=#custom but targetPort is missing', async (t) => { + await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() + + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() + + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test(`should print specific error when command doesn't exist`, async (t) => { + await withSiteBuilder('site-with-custom-framework', async (builder) => { + await builder.buildAsync() + + const error = await withDevServer( + { + cwd: builder.directory, + args: [ + '--command', + 'oops-i-did-it-again forgot-to-use-a-valid-command', + '--target-port', + '3000', + '--framework', + '#custom', + ], + }, + () => {}, + true, + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should prompt when multiple frameworks are detected', async (t) => { + await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { 'react-scripts': '1.0.0', gatsby: '^3.0.0' }, + scripts: { start: 'react-scripts start', develop: 'gatsby develop' }, + }, + }) + .withContentFile({ path: 'gatsby-config.js', content: '' }) + .buildAsync() + + // a failure is expected since this is not a true framework project + const asyncErrorBlock = async () => { + const childProcess = execa(cliPath, ['dev', '--offline'], getExecaOptions({ cwd: builder.directory })) + + handleQuestions(childProcess, [ + { + question: 'Multiple possible start commands found', + answer: answerWithValue(DOWN), + }, + ]) + + await childProcess + } + const error = await asyncErrorBlock().catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should not run framework detection if command and targetPort are configured', async (t) => { + await withSiteBuilder('site-with-hugo-config', async (builder) => { + await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() + + // a failure is expected since the command exits early + const error = await withDevServer( + { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, + () => {}, + true, + ).catch((error) => error) + + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should filter frameworks with no dev command', async (t) => { + await withSiteBuilder('site-with-gulp', async (builder) => { + await builder + .withContentFile({ + path: 'index.html', + content, + }) + .withPackageJson({ + packageJson: { dependencies: { gulp: '1.0.0' } }, + }) + .buildAsync() + + await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { + const response = await got(url).text() + t.expect(response).toEqual(content) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + }) + + test('should pass framework-info env to framework sub process', async (t) => { + await withSiteBuilder('site-with-gatsby', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { nuxt3: '^2.0.0' }, + scripts: { dev: 'node -p process.env.NODE_VERSION' }, + }, + }) + .buildAsync() + + // a failure is expected since this is not a true Gatsby project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() + }) + }) + + test('should start static service for frameworks without port, forced framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() + + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) + }) + + test('should start static service for frameworks without port, detected framework', async (t) => { + await withSiteBuilder('site-with-remix', async (builder) => { + await builder + .withPackageJson({ + packageJson: { + dependencies: { remix: '^1.0.0', '@remix-run/netlify': '^1.0.0' }, + scripts: {}, + }, + }) + .withContentFile({ path: 'remix.config.js', content: '' }) + .buildAsync() + + // a failure is expected since this is not a true remix project + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) + }) + }) + + test('should run and serve a production build when using the `serve` command', async (t) => { + await withSiteBuilder('site-with-framework', async (builder) => { + await builder + .withNetlifyToml({ + config: { + build: { publish: 'public' }, + context: { + dev: { environment: { CONTEXT_CHECK: 'DEV' } }, + production: { environment: { CONTEXT_CHECK: 'PRODUCTION' } }, + }, + functions: { directory: 'functions' }, + plugins: [{ package: './plugins/frameworker' }], + }, + }) + .withBuildPlugin({ + name: 'frameworker', + plugin: { + onPreBuild: async ({ netlifyConfig }) => { + // eslint-disable-next-line n/global-require + const { mkdir, writeFile } = require('fs').promises + + const generatedFunctionsDir = 'new_functions' + netlifyConfig.functions.directory = generatedFunctionsDir + + netlifyConfig.redirects.push({ + from: '/hello', + to: '/.netlify/functions/hello', + }) + + await mkdir(generatedFunctionsDir) + await writeFile( + `${generatedFunctionsDir}/hello.js`, + `const { CONTEXT_CHECK, NETLIFY_DEV } = process.env; exports.handler = async () => ({ statusCode: 200, body: JSON.stringify({ CONTEXT_CHECK, NETLIFY_DEV }) })`, + ) + }, + }, + }) + .buildAsync() + + await withDevServer( + { cwd: builder.directory, context: null, debug: true, serve: true }, + async ({ output, url }) => { + const response = await got(`${url}/hello`).json() + t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) + + t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() + }, + ) + }) + }) +}) \ No newline at end of file diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md deleted file mode 100644 index 24db116bc64..00000000000 --- a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.md +++ /dev/null @@ -1,302 +0,0 @@ -# Snapshot report for `tests/integration/frameworks/framework-detection.test.cjs` - -The actual snapshot is saved in `framework-detection.test.cjs.snap`. - -Generated by [AVA](https://avajs.dev). - -## should default to process.cwd() and static server - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when --dir flag is passed - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should use static server when framework is set to #static - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-index-file"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should log the command if using static server and `command` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should warn if using static server and `targetPort` is configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Using simple static server because '--dir' flag was specified␊ - ◈ Ignoring 'targetPort' setting since using a simple static server.␊ - ◈ Use --staticServerPort or [dev.staticServerPort] to configure the static server port␊ - ◈ Running static server from "site-with-index-file/public"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should run `command` when both `command` and `targetPort` are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should force a specific framework when configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ◈ Failed running command: react-scripts start. Please verify 'react-scripts' exists` - -## should throw when forcing a non supported framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Invalid framework "to-infinity-and-beyond-js". It should be one of: *` - -## should detect a known framework - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should throw if framework=#custom but command is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should throw if framework=#custom but targetPort is missing - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ 'command' and 'targetPort' properties are required when 'framework' is set to '#custom'` - -## should start custom command if framework=#custom, command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should print specific error when command doesn't exist - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with #custom␊ - ◈ Failed running command: oops-i-did-it-again forgot-to-use-a-valid-command. Please verify 'oops-i-did-it-again' exists` - -## should prompt when multiple frameworks are detected - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ? Multiple possible dev commands found (Use arrow keys or type to search)␊ - > [Gatsby] 'npm run develop' ␊ - [Create React App] 'npm run start' ? Multiple possible dev commands found ␊ - [Gatsby] 'npm run develop' ␊ - > [Create React App] 'npm run start' ? Multiple possible dev commands found Create React App-npm run start␊ - ␊ - Update your netlify.toml to avoid this selection prompt next time:␊ - ␊ - [build]␊ - command = "react-scripts build"␊ - publish = "build"␊ - ␊ - [dev]␊ - command = "npm run start"␊ - ␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with Create React App␊ - ␊ - > start␊ - > react-scripts start␊ - ␊ - ◈ Command failed with exit code *: npm run start. Shutting down Netlify Dev server` - -## should not run framework detection if command and targetPort are configured - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Setting up local development server␊ - ◈ Starting Netlify Dev with custom config␊ - hello␊ - ◈ "echo hello" exited with code *. Shutting down Netlify Dev server` - -## should filter frameworks with no dev command - -> Snapshot 1 - - `◈ Netlify Dev ◈␊ - ◈ No app server detected. Using simple static server␊ - ◈ Unable to determine public folder to serve files from. Using current working directory␊ - ◈ Setup a netlify.toml file with a [dev] section to specify your dev server settings.␊ - ◈ See docs at: https://cli.netlify.com/netlify-dev#project-detection␊ - ◈ Running static server from "site-with-gulp"␊ - ◈ Setting up local development server␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` - -## should run and serve a production build when using the `serve` command - -> Snapshot 1 - - `◈ Injected netlify.toml file env var: CONTEXT_CHECK␊ - ◈ Using simple static server because '[dev.framework]' was set to '#static'␊ - ◈ Running static server from "site-with-framework/public"␊ - ◈ Building site for production␊ - ◈ Changes will not be hot-reloaded, so if you need to rebuild your site you must exit and run 'netlify serve' again␊ - ​␊ - Netlify Build ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - > Version␊ - @netlify/build 0.0.0␊ - ​␊ - > Flags␊ - configPath:/file/path␊ - offline: true␊ - outputConfigPath:/file/path␊ - ​␊ - > Current directory␊ - /file/path␊ - ​␊ - > Config file␊ - /file/path␊ - ​␊ - > Context␊ - production␊ - ​␊ - > Loading plugins␊ - -/file/path from netlify.toml␊ - ​␊ - /file/path (onPreBuild event) ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Netlify configuration property "redirects" value changed to [ { from: /file/path', to: /file/path' } ].␊ - ​␊ - /file/path onPreBuild completed in Xms)␊ - ​␊ - Functions bundling ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - Packaging Functions from new_functions directory:␊ - - hello.js␊ - ​␊ - ​␊ - (Functions bundling completed in Xms)␊ - ​␊ - Save deploy artifacts ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - ​␊ - (Save deploy artifacts completed in Xms)␊ - ​␊ - Netlify Build Complete ␊ - ────────────────────────────────────────────────────────────────␊ - ​␊ - (Netlify Build completed in Xms)␊ - ␊ - ◈ Static server listening to 88888␊ - ␊ - ┌──────────────────────────────────────────────────┐␊ - │ │␊ - │ ◈ Server now ready on http://localhost:88888 │␊ - │ │␊ - └──────────────────────────────────────────────────┘` diff --git a/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap b/tests/integration/frameworks/snapshots/framework-detection.test.cjs.snap deleted file mode 100644 index d6ceebca537367d48a7b6b29b6de345f1638d859..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2053 zcmV+g2>SOyRzVY47H znPqLf7}y!lcz33%UcLJ2ecyXkvmd1WT*mwQFMs1EGdaKWgdWN=PaxqbD{})zLZM{L zwQk3gWNRCkNI)BAvKTa1W3DnSSb?LA{@n*j!VG)s%>U1v`spcpZ2aWZ&rbjQ%)P(< z5nkmc&(bMe=3~J3f&EMZD++H1r!+h^JZZxXorwYHY*ggDIhh@HL$E$JpldWljWWTZ zDEm3~N@bp)DQvR+AxhV@^Ae^^tBS*P4 z0+Y-Pv7wjn@g5qFO(un%r{FQIYbr}x!nj(E=Ek6X-S&1lBr?{(Ob3R>6uPss6X#jG znkbf|9shfTR?Z^mw{eolfr4{cGq06GSZL~)*yTY>XNE`QWt548--*cUR<$T{1#o4! z*(@hFc`l0);oxy~9UErzOdD>e!(~20k01bmdw2hQ@9w+b%jbK}zu&`sKXA}|ti#M= zAmjuTXUP7C=!-8Hx% zAv++IO|$KT4SPhM830y-n$8#4X-)Ap#lIgEf7w%9m7C1@Fm8kuGyGt&rH6!rO3;*Z<9)rPBx znDegBk?r_OJMehr`Ojz9wsd?!Z}$a-!69CL+1SHRzso%gF1pRZpG&sPX?@q%x~bc1 zYly<$$9o4vF|the+kDjUf2Og;SP0A@dhV>}UcWT+Qd`3))09{j5qzhy&vF%jp|=%U z*=gi&JaiTuQNtrMDUjm7De-iixX24^QWiSO@I;VAnTgndWi}HHq=_&`;CUfpk%4kb|YpUTY3n39$u*o7ZRn1f`@j>dynxU zOAOB~I-oE`LblJRnhqvrT5uOkOvS@(Oc}kGn9=>|9)wj2@LLc9R;s;&*{0Ud%1H>D zy(cei_Rc?jd9(NQ`7XYD0bkcPdrw?y{(R|(Uem0H_;m3;eL8>PA^3D~#;7shX78yB zm+8N55Zovd>S@W-;2eU^#xkSKVx>CwjPv0l_#G7QY{WZ3(Ce33p6msc%sdCJW@5MP zt-wlz9#XsiB(Q9*4{SKv3Vw_=$Td$qA&nhAuK;ISLs{;@QrcS^2Xfk4#E(J5kNuc- zt~#b=xv^I%GdZ^AgsiiEi7NlE5d{BS{|Ux-`<2k3%!~Ey*7|nq;oWXssoiebzrnKP zVw8@P(ow-|0%u1{%A#6uZmJu(RX7I>2A?bD5?&W}OZg zRdRY?nxZt_rM;cSu1`DjbOVch?06gK%UcbWy*OJvnrzdrFls2?io6_Tf*glvKHf!b zolACDt;3cSyNbKGzyu-8_K!IRDjrmIEUQiybagbP(}UY2-9o9!ODuRTT`dcH@LLOK zr?x-gIc#Zs0PnzF`yj|Qj8P6zq)6fLXnk{}w{71mrLdbyCl-<9w4o=CpSvvHX9HUL z91S17leg2^M>7_60*GA2+rF)>1$u2QfpR(K*V&kkuthGXK;?Fdr!jrPFt>;;2VyyB j%|z1meNGl=TTKuafm)Z<>#};q^Zl;@kMASU`7i(g$7}qy From 467aa3fba963158b78dae9ec421d5fe3b5795ecb Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 14:56:37 -0600 Subject: [PATCH 13/14] refactor: replace got with node-fetch --- .../frameworks/framework-detection.test.mjs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index c0c30004353..673d4e87c36 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -1,9 +1,9 @@ import execa from 'execa' +import fetch from 'node-fetch' import { describe, test } from 'vitest' import cliPath from '../utils/cli-path.cjs' import { getExecaOptions, withDevServer } from '../utils/dev-server.cjs' -import got from '../utils/got.cjs' import { DOWN, answerWithValue, handleQuestions } from '../utils/handle-questions.cjs' import { withSiteBuilder } from '../utils/site-builder.cjs' import { normalize } from '../utils/snapshots.cjs' @@ -21,7 +21,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -39,7 +39,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory, args: ['--dir', 'public'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -58,7 +58,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -78,7 +78,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--command', 'npm run start'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -99,7 +99,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, args: ['--dir', 'public', '--target-port', '3000'] }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -277,7 +277,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() await withDevServer({ cwd: builder.directory }, async ({ output, url }) => { - const response = await got(url).text() + const response = await fetch(url).then((res) => res.text()) t.expect(response).toEqual(content) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() @@ -372,7 +372,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withDevServer( { cwd: builder.directory, context: null, debug: true, serve: true }, async ({ output, url }) => { - const response = await got(`${url}/hello`).json() + const response = await fetch(`${url}/hello`).then((res) => res.json()) t.expect(response).toStrictEqual({ CONTEXT_CHECK: 'PRODUCTION' }) t.expect(normalize(output, { duration: true, filePath: true })).toMatchSnapshot() From 90fe74fcc576f254784aaa283f2c79e67f7dd4db Mon Sep 17 00:00:00 2001 From: Angel Mendez Date: Thu, 3 Aug 2023 15:00:02 -0600 Subject: [PATCH 14/14] style: apply lint rules --- .../frameworks/framework-detection.test.mjs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integration/frameworks/framework-detection.test.mjs b/tests/integration/frameworks/framework-detection.test.mjs index 673d4e87c36..b80de082664 100644 --- a/tests/integration/frameworks/framework-detection.test.mjs +++ b/tests/integration/frameworks/framework-detection.test.mjs @@ -117,7 +117,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -128,7 +128,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'create-react-app' } } }).buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -137,7 +137,7 @@ describe.concurrent('frameworks/framework-detection', () => { await withSiteBuilder('site-with-unknown-framework', async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: 'to-infinity-and-beyond-js' } } }).buildAsync() - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -151,7 +151,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true create-react-app project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -164,7 +164,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -177,7 +177,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -190,7 +190,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -213,7 +213,7 @@ describe.concurrent('frameworks/framework-detection', () => { }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -244,7 +244,7 @@ describe.concurrent('frameworks/framework-detection', () => { await childProcess } - const error = await asyncErrorBlock().catch((error) => error) + const error = await asyncErrorBlock().catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -258,7 +258,7 @@ describe.concurrent('frameworks/framework-detection', () => { { cwd: builder.directory, args: ['--command', 'echo hello', '--target-port', '3000'] }, () => {}, true, - ).catch((error) => error) + ).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) @@ -297,7 +297,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true Gatsby project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(normalize(error.stdout, { duration: true, filePath: true })).toMatchSnapshot() }) }) @@ -307,7 +307,7 @@ describe.concurrent('frameworks/framework-detection', () => { await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -325,7 +325,7 @@ describe.concurrent('frameworks/framework-detection', () => { .buildAsync() // a failure is expected since this is not a true remix project - const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error) => error) + const error = await withDevServer({ cwd: builder.directory }, () => {}, true).catch((error_) => error_) t.expect(error.stdout.includes(`Failed running command: remix watch. Please verify 'remix' exists`)).toBe(true) }) }) @@ -348,7 +348,7 @@ describe.concurrent('frameworks/framework-detection', () => { name: 'frameworker', plugin: { onPreBuild: async ({ netlifyConfig }) => { - // eslint-disable-next-line n/global-require + // eslint-disable-next-line n/global-require, no-undef const { mkdir, writeFile } = require('fs').promises const generatedFunctionsDir = 'new_functions'