From fa5de3b866f20a7814d52229c98d09be2ec1b156 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 8 May 2024 12:41:37 +0200 Subject: [PATCH 1/4] fix: execute each test in unique folder --- tests/integration/framework-detection.test.js | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/integration/framework-detection.test.js b/tests/integration/framework-detection.test.js index 1ab1ce5a12b..8b77468f88a 100644 --- a/tests/integration/framework-detection.test.js +++ b/tests/integration/framework-detection.test.js @@ -12,7 +12,7 @@ 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 withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'index.html', @@ -30,7 +30,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should use static server when --dir flag is passed', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'public/index.html', @@ -48,7 +48,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should use static server when framework is set to #static', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'index.html', @@ -70,7 +70,7 @@ describe.concurrent('frameworks/framework-detection', () => { // Running it in isolation (or removing the '.concurrent' on the describe block above) // fixes it. See CT-1094 for more details test('should log the command if using static server and `command` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'public/index.html', @@ -91,7 +91,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should warn if using static server and `targetPort` is configured', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'public/index.html', @@ -112,7 +112,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should run `command` when both `command` and `targetPort` are configured', async (t) => { - await withSiteBuilder('empty-site', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withNetlifyToml({ config: { build: { publish: 'public' } } }).buildAsync() // a failure is expected since we use `echo hello` instead of starting a server @@ -127,7 +127,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should force a specific framework when configured', async (t) => { - await withSiteBuilder('site-with-mocked-cra', async (builder) => { + await withSiteBuilder(t, 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 @@ -137,7 +137,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should throw when forcing a non supported framework', async (t) => { - await withSiteBuilder('site-with-unknown-framework', async (builder) => { + await withSiteBuilder(t, 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_) @@ -146,7 +146,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should detect a known framework', async (t) => { - await withSiteBuilder('site-with-cra', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { dependencies: { 'react-scripts': '1.0.0' }, scripts: { start: 'react-scripts start' } }, @@ -173,7 +173,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should throw if framework=#custom but targetPort is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() const error = await withDevServer( @@ -186,7 +186,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should start custom command if framework=#custom, command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: '#custom', publish: 'public' } } }).buildAsync() const error = await withDevServer( @@ -199,7 +199,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test(`should print specific error when command doesn't exist`, async (t) => { - await withSiteBuilder('site-with-custom-framework', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() const error = await withDevServer( @@ -223,7 +223,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should prompt when multiple frameworks are detected', async (t) => { - await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { @@ -257,7 +257,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should fail in CI when multiple frameworks are detected', async (t) => { - await withSiteBuilder('site-with-multiple-frameworks', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { @@ -288,7 +288,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should not run framework detection if command and targetPort are configured', async (t) => { - await withSiteBuilder('site-with-hugo-config', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withContentFile({ path: 'config.toml', content: '' }).buildAsync() // a failure is expected since the command exits early @@ -303,7 +303,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should filter frameworks with no dev command', async (t) => { - await withSiteBuilder('site-with-gulp', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'index.html', @@ -324,7 +324,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should pass framework-info env to framework sub process', async (t) => { - await withSiteBuilder('site-with-gatsby', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { @@ -341,7 +341,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should start static service for frameworks without port, forced framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: 'remix' } } }).buildAsync() // a failure is expected since this is not a true remix project @@ -351,7 +351,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should start static service for frameworks without port, detected framework', async (t) => { - await withSiteBuilder('site-with-remix', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { @@ -369,7 +369,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should run and serve a production build when using the `serve` command', async (t) => { - await withSiteBuilder('site-with-framework', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { From f62520320b8840b988768b69a2b8534bba8ce920 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 8 May 2024 12:45:05 +0200 Subject: [PATCH 2/4] fix: remove string site name --- .../integration/commands/build/build.test.js | 2 +- .../dev/dev-forms-and-redirects.test.js | 26 ++++++++--------- .../commands/dev/dev-miscellaneous.test.js | 2 +- .../integration/commands/dev/dev.exec.test.js | 2 +- .../commands/dev/responses.dev.test.js | 22 +++++++-------- .../functions-create/functions-create.test.ts | 12 ++++---- .../functions-serve/functions-serve.test.js | 10 +++---- .../commands/integration/deploy.test.ts | 2 +- tests/integration/framework-detection.test.js | 2 +- tests/integration/serve/functions-go.test.js | 4 +-- .../integration/serve/functions-rust.test.js | 2 +- tests/integration/telemetry.test.ts | 2 +- tests/integration/utils/site-builder.ts | 14 ++-------- tests/unit/utils/deploy/hash-files.test.js | 4 +-- tests/unit/utils/deploy/hash-fns.test.js | 4 +-- tests/unit/utils/dot-env.test.js | 28 +++++++++---------- .../utils/functions/get-functions.test.js | 4 +-- tests/unit/utils/redirects.test.js | 12 ++++---- 18 files changed, 72 insertions(+), 82 deletions(-) diff --git a/tests/integration/commands/build/build.test.js b/tests/integration/commands/build/build.test.js index e24a6dc7206..9a325e0c8d7 100644 --- a/tests/integration/commands/build/build.test.js +++ b/tests/integration/commands/build/build.test.js @@ -293,7 +293,7 @@ describe.concurrent('command/build', () => { }) test('should have version in NETLIFY_CLI_VERSION variable', async (t) => { - await withSiteBuilder('NETLIFY_CLI_VERSION-env', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { diff --git a/tests/integration/commands/dev/dev-forms-and-redirects.test.js b/tests/integration/commands/dev/dev-forms-and-redirects.test.js index fc3ba6f12cf..194cbc9c6b9 100644 --- a/tests/integration/commands/dev/dev-forms-and-redirects.test.js +++ b/tests/integration/commands/dev/dev-forms-and-redirects.test.js @@ -12,7 +12,7 @@ import { withSiteBuilder } from '../../utils/site-builder.ts' describe.concurrent('commands/dev-forms-and-redirects', () => { test('should return 404 when redirecting to a non existing function', async (t) => { - await withSiteBuilder('site-with-missing-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { functions: { directory: 'functions' }, @@ -34,7 +34,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should parse function query parameters using simple parsing', async (t) => { - await withSiteBuilder('site-with-multi-part-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { @@ -64,7 +64,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should handle form submission', async (t) => { - await withSiteBuilder('site-with-form', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'index.html', @@ -129,7 +129,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should handle form submission with a background function', async (t) => { - await withSiteBuilder('site-with-form-background-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withContentFile({ path: 'index.html', @@ -163,7 +163,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should not handle form submission when content type is `text/plain`', async (t) => { - await withSiteBuilder('site-with-form-text-plain', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'index.html', @@ -199,7 +199,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should return existing local file even when rewrite matches when force=false', async (t) => { - await withSiteBuilder('site-with-shadowing-force-false', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -225,7 +225,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should return existing local file even when redirect matches when force=false', async (t) => { - await withSiteBuilder('site-with-shadowing-force-false', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -251,7 +251,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should ignore existing local file when redirect matches and force=true', async (t) => { - await withSiteBuilder('site-with-shadowing-force-true', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -282,7 +282,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should use existing file when rule contains file extension and force=false', async (t) => { - await withSiteBuilder('site-with-shadowing-file-extension-force-false', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -309,7 +309,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should redirect when rule contains file extension and force=true', async (t) => { - await withSiteBuilder('site-with-shadowing-file-extension-force-true', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -340,7 +340,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { }) test('should redirect from sub directory to root directory', async (t) => { - await withSiteBuilder('site-with-shadowing-sub-to-root', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withContentFile({ path: 'foo.html', @@ -419,7 +419,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { await fs.writeFile(path.join(pluginDirectory, 'manifest.yml'), pluginManifest) await fs.writeFile(path.join(pluginDirectory, 'index.js'), pluginSource) - await withSiteBuilder('site-with-custom-server-in-plugin', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { @@ -476,7 +476,7 @@ describe.concurrent('commands/dev-forms-and-redirects', () => { await fs.writeFile(path.join(pluginDirectory, 'manifest.yml'), pluginManifest) await fs.writeFile(path.join(pluginDirectory, 'index.js'), pluginSource) - await withSiteBuilder('site-with-custom-server-in-plugin', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { diff --git a/tests/integration/commands/dev/dev-miscellaneous.test.js b/tests/integration/commands/dev/dev-miscellaneous.test.js index ba6f03dbb07..a63cdb7b60d 100644 --- a/tests/integration/commands/dev/dev-miscellaneous.test.js +++ b/tests/integration/commands/dev/dev-miscellaneous.test.js @@ -1323,7 +1323,7 @@ describe.concurrent('commands/dev-miscellaneous', () => { }) test('should fail in CI with multiple projects', async (t) => { - await withSiteBuilder('site-with-multiple-packages', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withPackageJson({ packageJson: { name: 'main', workspaces: ['*'] } }) .withPackageJson({ packageJson: { name: 'package1' }, pathPrefix: 'package1' }) diff --git a/tests/integration/commands/dev/dev.exec.test.js b/tests/integration/commands/dev/dev.exec.test.js index f20f6726269..7f69e34c594 100644 --- a/tests/integration/commands/dev/dev.exec.test.js +++ b/tests/integration/commands/dev/dev.exec.test.js @@ -6,7 +6,7 @@ import { callCli } from '../../utils/call-cli.js' import { withSiteBuilder } from '../../utils/site-builder.ts' test('should pass .env variables to exec command', async (t) => { - await withSiteBuilder('site-env-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ env: { MY_SUPER_SECRET: 'SECRET' } }) await builder.buildAsync() diff --git a/tests/integration/commands/dev/responses.dev.test.js b/tests/integration/commands/dev/responses.dev.test.js index ba4acc249f3..fcb6940486b 100644 --- a/tests/integration/commands/dev/responses.dev.test.js +++ b/tests/integration/commands/dev/responses.dev.test.js @@ -9,7 +9,7 @@ import { withSiteBuilder } from '../../utils/site-builder.ts' describe.concurrent('commands/responses.dev', () => { test('should return index file when / is accessed', async (t) => { - await withSiteBuilder('site-with-index-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withContentFile({ path: 'index.html', content: '

⊂◉‿◉つ

', @@ -25,7 +25,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should return user defined headers when / is accessed', async (t) => { - await withSiteBuilder('site-with-headers-on-root', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withContentFile({ path: 'index.html', content: '

⊂◉‿◉つ

', @@ -45,7 +45,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should return user defined headers when non-root path is accessed', async (t) => { - await withSiteBuilder('site-with-headers-on-non-root', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withContentFile({ path: 'foo/index.html', content: '

⊂◉‿◉つ

', @@ -65,7 +65,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should return response from a function with setTimeout', async (t) => { - await withSiteBuilder('site-with-set-timeout-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({ path: 'timeout.js', handler: async () => { @@ -97,7 +97,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should fail when no metadata is set for builder function', async (t) => { - await withSiteBuilder('site-with-misconfigured-builder-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({ path: 'builder.js', handler: async () => ({ @@ -125,7 +125,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should serve function from a subdirectory', async (t) => { - await withSiteBuilder('site-with-from-subdirectory', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({ path: path.join('echo', 'echo.js'), handler: async (event) => ({ @@ -149,7 +149,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should pass .env.development vars to function', async (t) => { - await withSiteBuilder('site-with-env-development', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { functions: { directory: 'functions' } } }) .withEnvFile({ path: '.env.development', env: { ENV_DEV_TEST: 'FROM_DEV_FILE' } }) @@ -178,7 +178,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should pass process env vars to function', async (t) => { - await withSiteBuilder('site-with-process-env', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { functions: { directory: 'functions' } } }).withFunction({ path: 'env.js', handler: async () => ({ @@ -204,7 +204,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should pass [build.environment] env vars to function', async (t) => { - await withSiteBuilder('site-with-build-environment', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { @@ -236,7 +236,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('[context.dev.environment] should override [build.environment]', async (t) => { - await withSiteBuilder('site-with-build-environment', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { @@ -264,7 +264,7 @@ describe.concurrent('commands/responses.dev', () => { }) test('should inject env vars based on [dev].envFiles file order', async (t) => { - await withSiteBuilder('site-with-env-files', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withNetlifyToml({ config: { diff --git a/tests/integration/commands/functions-create/functions-create.test.ts b/tests/integration/commands/functions-create/functions-create.test.ts index c8abcc3e5e9..7a10bce4bfc 100644 --- a/tests/integration/commands/functions-create/functions-create.test.ts +++ b/tests/integration/commands/functions-create/functions-create.test.ts @@ -36,7 +36,7 @@ describe.concurrent('functions:create command', () => { ] test('should create a new function directory when none is found', async () => { - await withSiteBuilder('site-with-no-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() await withMockApi(routes, async ({ apiUrl }) => { const childProcess = execa(cliPath, ['functions:create'], getCLIOptions({ apiUrl, builder })) @@ -72,7 +72,7 @@ describe.concurrent('functions:create command', () => { }) test('should create a new edge function directory when none is found', async () => { - await withSiteBuilder('site-with-no-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() await withMockApi(routes, async ({ apiUrl }) => { const childProcess = execa(cliPath, ['functions:create'], getCLIOptions({ apiUrl, builder })) @@ -108,7 +108,7 @@ describe.concurrent('functions:create command', () => { }) test('should use specified edge function directory when found', async () => { - await withSiteBuilder('site-with-custom-edge-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { build: { edge_functions: 'somethingEdgy' } } }) await builder.buildAsync() await withMockApi(routes, async ({ apiUrl }) => { @@ -144,7 +144,7 @@ describe.concurrent('functions:create command', () => { }) test('should not create a new function directory when one is found', async () => { - await withSiteBuilder('site-with-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { build: { functions: 'functions' } } }) await builder.buildAsync() @@ -182,7 +182,7 @@ describe.concurrent('functions:create command', () => { test('should only show function templates for the language specified via the --language flag, if one is present', async () => { const createWithLanguageTemplate = async (language, outputPath) => - await withSiteBuilder('site-with-no-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() const createFunctionQuestions = [ @@ -224,7 +224,7 @@ describe.concurrent('functions:create command', () => { }) test('throws an error when the --language flag contains an unsupported value', async () => { - await withSiteBuilder('site-with-no-functions-dir', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() const createFunctionQuestions = [ diff --git a/tests/integration/commands/functions-serve/functions-serve.test.js b/tests/integration/commands/functions-serve/functions-serve.test.js index bf2c5191df1..23ee2f0449b 100644 --- a/tests/integration/commands/functions-serve/functions-serve.test.js +++ b/tests/integration/commands/functions-serve/functions-serve.test.js @@ -37,7 +37,7 @@ const withFunctionsServer = async ({ args = [], builder, port = DEFAULT_PORT }, describe.concurrent('functions:serve command', () => { test('should serve functions on default port', async (t) => { - await withSiteBuilder('site-with-ping-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { functions: { directory: 'functions' } } }) .withFunction({ @@ -57,7 +57,7 @@ describe.concurrent('functions:serve command', () => { }) test('should serve functions on custom port', async (t) => { - await withSiteBuilder('site-with-ping-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { functions: { directory: 'functions' } } }) .withFunction({ @@ -78,7 +78,7 @@ describe.concurrent('functions:serve command', () => { }) test('should use settings from netlify.toml dev', async (t) => { - await withSiteBuilder('site-with-ping-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { const port = await getPort() await builder .withNetlifyToml({ @@ -102,7 +102,7 @@ describe.concurrent('functions:serve command', () => { }) test('should inject env variables', async (t) => { - await withSiteBuilder('site-with-env-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { @@ -129,7 +129,7 @@ describe.concurrent('functions:serve command', () => { }) test('should handle content-types with charset', async (t) => { - await withSiteBuilder('site-with-env-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { functions: { directory: 'functions' } }, diff --git a/tests/integration/commands/integration/deploy.test.ts b/tests/integration/commands/integration/deploy.test.ts index d0b526b2b47..6a7cc7396be 100644 --- a/tests/integration/commands/integration/deploy.test.ts +++ b/tests/integration/commands/integration/deploy.test.ts @@ -63,7 +63,7 @@ describe(`integration:deploy`, () => { }, ] - await withSiteBuilder('my-integration', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withContentFiles([ { path: 'integration.yaml', diff --git a/tests/integration/framework-detection.test.js b/tests/integration/framework-detection.test.js index 8b77468f88a..8d56b7a8e1b 100644 --- a/tests/integration/framework-detection.test.js +++ b/tests/integration/framework-detection.test.js @@ -160,7 +160,7 @@ describe.concurrent('frameworks/framework-detection', () => { }) test('should throw if framework=#custom but command is missing', async (t) => { - await withSiteBuilder('site-with-framework-and-no-command', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withNetlifyToml({ config: { dev: { framework: '#custom' } } }).buildAsync() const error = await withDevServer( diff --git a/tests/integration/serve/functions-go.test.js b/tests/integration/serve/functions-go.test.js index b8f4d956746..ec30898ec98 100644 --- a/tests/integration/serve/functions-go.test.js +++ b/tests/integration/serve/functions-go.test.js @@ -50,7 +50,7 @@ describe.concurrent('serve/functions-go', () => { }) `) - await withSiteBuilder('go-function-update', async (builder) => { + await withSiteBuilder(t, async (builder) => { try { await builder .withNetlifyToml({ @@ -138,7 +138,7 @@ describe.concurrent('serve/functions-go', () => { }) `) - await withSiteBuilder('go-scheduled-function', async (builder) => { + await withSiteBuilder(t, async (builder) => { try { await builder .withNetlifyToml({ diff --git a/tests/integration/serve/functions-rust.test.js b/tests/integration/serve/functions-rust.test.js index dcbe8e8e46d..58f11804cbc 100644 --- a/tests/integration/serve/functions-rust.test.js +++ b/tests/integration/serve/functions-rust.test.js @@ -9,7 +9,7 @@ import { withSiteBuilder } from '../utils/site-builder.ts' const WAIT_WRITE = 1000 test('Updates a Rust function when a file is modified', async (t) => { - await withSiteBuilder('rust-function-update', async (builder) => { + await withSiteBuilder(t, async (builder) => { const originalBody = 'Netlify likes Rust' const updatedBody = 'Netlify *loves* Rust' diff --git a/tests/integration/telemetry.test.ts b/tests/integration/telemetry.test.ts index bbfd2994eb6..eea84cf9473 100644 --- a/tests/integration/telemetry.test.ts +++ b/tests/integration/telemetry.test.ts @@ -100,7 +100,7 @@ await withMockApi(routes, async () => { }) test('should add frameworks, buildSystem, and packageManager', async ({ apiUrl, requests }) => { - await withSiteBuilder('nextjs-site', async (builder) => { + await withSiteBuilder(t, async (builder) => { await builder.withPackageJson({ packageJson: { dependencies: { next: '^12.13.0' } } }).buildAsync() await execa(cliPath, ['api', 'listSites'], { diff --git a/tests/integration/utils/site-builder.ts b/tests/integration/utils/site-builder.ts index 3a126a2242b..254c448fa1a 100644 --- a/tests/integration/utils/site-builder.ts +++ b/tests/integration/utils/site-builder.ts @@ -294,26 +294,16 @@ export const createSiteBuilder = ({ siteName }: { siteName: string }) => { return new SiteBuilder(directory).ensureDirectoryExists(directory) } -/** - * @deprecated use the task-based signature instead - */ -export function withSiteBuilder(siteName: string, testHandler: (builder: SiteBuilder) => Promise): Promise /** * @param taskContext used to infer directory name from test name */ -export function withSiteBuilder( - taskContext: TaskContext, - testHandler: (builder: SiteBuilder) => Promise, -): Promise export async function withSiteBuilder( - siteNameOrTaskContext: string | TaskContext, + taskContext: TaskContext, testHandler: (builder: SiteBuilder) => Promise, ): Promise { let builder: SiteBuilder | undefined try { - const siteName = - typeof siteNameOrTaskContext === 'string' ? siteNameOrTaskContext : slugify(siteNameOrTaskContext.task.name) - builder = createSiteBuilder({ siteName }) + builder = createSiteBuilder({ siteName: slugify(taskContext.task.name) }) return await testHandler(builder) } finally { if (builder) await builder.cleanup() diff --git a/tests/unit/utils/deploy/hash-files.test.js b/tests/unit/utils/deploy/hash-files.test.js index 9b3c2e2ba68..1bbfb0929ec 100644 --- a/tests/unit/utils/deploy/hash-files.test.js +++ b/tests/unit/utils/deploy/hash-files.test.js @@ -4,8 +4,8 @@ import { DEFAULT_CONCURRENT_HASH } from '../../../../dist/utils/deploy/constants import hashFiles from '../../../../dist/utils/deploy/hash-files.js' import { withSiteBuilder } from '../../../integration/utils/site-builder.ts' -test('Hashes files in a folder', async () => { - await withSiteBuilder('site-with-content', async (builder) => { +test('Hashes files in a folder', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { build: { publish: 'public' } } }) .withContentFile({ diff --git a/tests/unit/utils/deploy/hash-fns.test.js b/tests/unit/utils/deploy/hash-fns.test.js index 1c22c620a32..84f13e7977e 100644 --- a/tests/unit/utils/deploy/hash-fns.test.js +++ b/tests/unit/utils/deploy/hash-fns.test.js @@ -6,8 +6,8 @@ import { DEFAULT_CONCURRENT_HASH } from '../../../../dist/utils/deploy/constants import hashFns from '../../../../dist/utils/deploy/hash-fns.js' import { withSiteBuilder } from '../../../integration/utils/site-builder.ts' -test('Hashes files in a folder', async () => { - await withSiteBuilder('site-with-functions', async (builder) => { +test('Hashes files in a folder', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: { functions: { directory: 'functions' } } }) .withFunction({ diff --git a/tests/unit/utils/dot-env.test.js b/tests/unit/utils/dot-env.test.js index 7accdf3128b..e72bfda510a 100644 --- a/tests/unit/utils/dot-env.test.js +++ b/tests/unit/utils/dot-env.test.js @@ -5,8 +5,8 @@ import { expect, test } from 'vitest' import { tryLoadDotEnvFiles } from '../../../dist/utils/dot-env.js' import { withSiteBuilder } from '../../integration/utils/site-builder.ts' -test('should return an empty array for a site with no .env file', async () => { - await withSiteBuilder('site-without-env-file', async (builder) => { +test('should return an empty array for a site with no .env file', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder.buildAsync() const results = await tryLoadDotEnvFiles({ projectDir: builder.directory }) @@ -14,9 +14,9 @@ test('should return an empty array for a site with no .env file', async () => { }) }) -test('should read env vars from .env file', async () => { +test('should read env vars from .env file', async (t) => { process.env.NODE_ENV = 'development' - await withSiteBuilder('site-with-envs-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ path: '.env', env: { TEST: 'FROM_ENV' }, @@ -28,9 +28,9 @@ test('should read env vars from .env file', async () => { }) }) -test('should read env vars from .env.development file', async () => { +test('should read env vars from .env.development file', async (t) => { process.env.NODE_ENV = 'development' - await withSiteBuilder('site-with-envs-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ path: '.env.development', env: { TEST: 'FROM_DEVELOPMENT_ENV' }, @@ -42,9 +42,9 @@ test('should read env vars from .env.development file', async () => { }) }) -test('should read env vars from .env.local file', async () => { +test('should read env vars from .env.local file', async (t) => { process.env.NODE_ENV = 'development' - await withSiteBuilder('site-with-envs-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ path: '.env.local', env: { TEST: 'FROM_LOCAL_ENV' }, @@ -56,9 +56,9 @@ test('should read env vars from .env.local file', async () => { }) }) -test('should read env vars from .env.development.local file', async () => { +test('should read env vars from .env.development.local file', async (t) => { process.env.NODE_ENV = 'development' - await withSiteBuilder('site-with-envs-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ path: '.env.development.local', env: { TEST: 'FROM_LOCAL_DEVELOPMENT_ENV' }, @@ -70,9 +70,9 @@ test('should read env vars from .env.development.local file', async () => { }) }) -test('should read env vars from all four .env[.development][.local] files', async () => { +test('should read env vars from all four .env[.development][.local] files', async (t) => { process.env.NODE_ENV = 'development' - await withSiteBuilder('site-with-envs-file', async (builder) => { + await withSiteBuilder(t, async (builder) => { builder .withEnvFile({ path: '.env', @@ -105,8 +105,8 @@ test('should read env vars from all four .env[.development][.local] files', asyn }) }) -test('should handle empty .env file', async () => { - await withSiteBuilder('site-with-empty-env-file', async (builder) => { +test('should handle empty .env file', async (t) => { + await withSiteBuilder(t, async (builder) => { builder.withEnvFile({ path: '.env', }) diff --git a/tests/unit/utils/functions/get-functions.test.js b/tests/unit/utils/functions/get-functions.test.js index cdd10b0acce..2c2a229ce71 100644 --- a/tests/unit/utils/functions/get-functions.test.js +++ b/tests/unit/utils/functions/get-functions.test.js @@ -43,8 +43,8 @@ describe('getFunctions', () => { }) }) - test('should mark background functions based on filenames', async () => { - await withSiteBuilder('site-without-functions', async (builder) => { + test('should mark background functions based on filenames', async (t) => { + await withSiteBuilder(t, async (builder) => { builder .withFunction({ path: 'foo-background.js', diff --git a/tests/unit/utils/redirects.test.js b/tests/unit/utils/redirects.test.js index e7618d4b7ef..897524f43ea 100644 --- a/tests/unit/utils/redirects.test.js +++ b/tests/unit/utils/redirects.test.js @@ -56,8 +56,8 @@ const BASE_REDIRECT = { params: {}, } -test('should parse redirect rules from netlify.toml', async () => { - await withSiteBuilder('site-with-redirects-in-netlify-toml', async (builder) => { +test('should parse redirect rules from netlify.toml', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder .withNetlifyToml({ config: defaultConfig, @@ -124,8 +124,8 @@ test('should parse redirect rules from netlify.toml', async () => { }) }) -test('should parse redirect rules from _redirects file', async () => { - await withSiteBuilder('site-with-redirects-file', async (builder) => { +test('should parse redirect rules from _redirects file', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder .withRedirectsFile({ redirects: defaultRedirects, @@ -147,8 +147,8 @@ test('should parse redirect rules from _redirects file', async () => { }) }) -test('should parse redirect rules from _redirects file and netlify.toml', async () => { - await withSiteBuilder('site-with-redirects-file-and-netlify-toml', async (builder) => { +test('should parse redirect rules from _redirects file and netlify.toml', async (t) => { + await withSiteBuilder(t, async (builder) => { await builder .withRedirectsFile({ redirects: defaultRedirects, From 6822a0de6e8f38a91e0726ccfb6cb32c415dfa15 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 8 May 2024 13:19:33 +0200 Subject: [PATCH 3/4] fix: add some missing Tea --- .../functions-create/functions-create.test.ts | 12 ++++++------ .../integration/commands/integration/deploy.test.ts | 2 +- tests/integration/telemetry.test.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/integration/commands/functions-create/functions-create.test.ts b/tests/integration/commands/functions-create/functions-create.test.ts index 7a10bce4bfc..d43f92c9152 100644 --- a/tests/integration/commands/functions-create/functions-create.test.ts +++ b/tests/integration/commands/functions-create/functions-create.test.ts @@ -35,7 +35,7 @@ describe.concurrent('functions:create command', () => { { path: 'sites/site_id', method: 'patch', response: {} }, ] - test('should create a new function directory when none is found', async () => { + test('should create a new function directory when none is found', async (t) => { await withSiteBuilder(t, async (builder) => { await builder.buildAsync() await withMockApi(routes, async ({ apiUrl }) => { @@ -71,7 +71,7 @@ describe.concurrent('functions:create command', () => { }) }) - test('should create a new edge function directory when none is found', async () => { + test('should create a new edge function directory when none is found', async (t) => { await withSiteBuilder(t, async (builder) => { await builder.buildAsync() await withMockApi(routes, async ({ apiUrl }) => { @@ -107,7 +107,7 @@ describe.concurrent('functions:create command', () => { }) }) - test('should use specified edge function directory when found', async () => { + test('should use specified edge function directory when found', async (t) => { await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { build: { edge_functions: 'somethingEdgy' } } }) await builder.buildAsync() @@ -143,7 +143,7 @@ describe.concurrent('functions:create command', () => { }) }) - test('should not create a new function directory when one is found', async () => { + test('should not create a new function directory when one is found', async (t) => { await withSiteBuilder(t, async (builder) => { builder.withNetlifyToml({ config: { build: { functions: 'functions' } } }) @@ -180,7 +180,7 @@ describe.concurrent('functions:create command', () => { }) }) - test('should only show function templates for the language specified via the --language flag, if one is present', async () => { + test('should only show function templates for the language specified via the --language flag, if one is present', async (t) => { const createWithLanguageTemplate = async (language, outputPath) => await withSiteBuilder(t, async (builder) => { await builder.buildAsync() @@ -223,7 +223,7 @@ describe.concurrent('functions:create command', () => { await createWithLanguageTemplate('typescript', 'hello-world/hello-world.ts') }) - test('throws an error when the --language flag contains an unsupported value', async () => { + test('throws an error when the --language flag contains an unsupported value', async (t) => { await withSiteBuilder(t, async (builder) => { await builder.buildAsync() diff --git a/tests/integration/commands/integration/deploy.test.ts b/tests/integration/commands/integration/deploy.test.ts index 6a7cc7396be..950586da41a 100644 --- a/tests/integration/commands/integration/deploy.test.ts +++ b/tests/integration/commands/integration/deploy.test.ts @@ -28,7 +28,7 @@ describe(`integration:deploy`, () => { beforeEach(() => { vi.resetAllMocks() }) - test('deploys an integration', async () => { + test('deploys an integration', async (t) => { vi.mock(`../../../../src/commands/deploy/deploy.js`, () => ({ deploy: vi.fn(() => console.log(`yay it was mocked!`)), })) diff --git a/tests/integration/telemetry.test.ts b/tests/integration/telemetry.test.ts index eea84cf9473..6045e5aebb0 100644 --- a/tests/integration/telemetry.test.ts +++ b/tests/integration/telemetry.test.ts @@ -99,16 +99,16 @@ await withMockApi(routes, async () => { }) }) - test('should add frameworks, buildSystem, and packageManager', async ({ apiUrl, requests }) => { + test('should add frameworks, buildSystem, and packageManager', async (t) => { await withSiteBuilder(t, async (builder) => { await builder.withPackageJson({ packageJson: { dependencies: { next: '^12.13.0' } } }).buildAsync() await execa(cliPath, ['api', 'listSites'], { cwd: builder.directory, - ...getCLIOptions(apiUrl), + ...getCLIOptions(t.apiUrl), }) - const request = requests.find(({ path }) => path === '/api/v1/track') + const request = t.requests.find(({ path }) => path === '/api/v1/track') expect(request).toBeDefined() expect(typeof request.body.anonymousId).toBe('string') From 3842b43482e51cd2cd4d96a13ff53e9311b7a487 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 8 May 2024 13:22:28 +0200 Subject: [PATCH 4/4] fix: snapshot --- .../__snapshots__/framework-detection.test.js.snap | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/integration/__snapshots__/framework-detection.test.js.snap b/tests/integration/__snapshots__/framework-detection.test.js.snap index 95c47bd12ac..54fb0c89f92 100644 --- a/tests/integration/__snapshots__/framework-detection.test.js.snap +++ b/tests/integration/__snapshots__/framework-detection.test.js.snap @@ -6,7 +6,7 @@ exports[`frameworks/framework-detection > should default to process.cwd() and st ◈ 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://docs.netlify.com/cli/local-development/#project-detection -◈ Running static server from \\"site-with-index-file\\" +◈ Running static server from \\"should-default-to-process-cwd-and-static-server\\" ◈ Setting up local development server ◈ Static server listening to 88888 @@ -35,7 +35,7 @@ exports[`frameworks/framework-detection > should filter frameworks with no dev c ◈ 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://docs.netlify.com/cli/local-development/#project-detection -◈ Running static server from \\"site-with-gulp\\" +◈ Running static server from \\"should-filter-frameworks-with-no-dev-command\\" ◈ Setting up local development server ◈ Static server listening to 88888 @@ -57,7 +57,7 @@ exports[`frameworks/framework-detection > should force a specific framework when 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\\" +◈ Running static server from \\"should-log-the-command-if-using-static-server-and-command-is-configured/public\\" ◈ Setting up local development server ◈ Static server listening to 88888 @@ -162,7 +162,7 @@ exports[`frameworks/framework-detection > should throw when forcing a non suppor 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\\" +◈ Running static server from \\"should-use-static-server-when-dir-flag-is-passed/public\\" ◈ Setting up local development server ◈ Static server listening to 88888 @@ -180,7 +180,7 @@ exports[`frameworks/framework-detection > should use static server when framewor ◈ 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://docs.netlify.com/cli/local-development/#project-detection -◈ Running static server from \\"site-with-index-file\\" +◈ Running static server from \\"should-use-static-server-when-framework-is-set-to-static\\" ◈ Setting up local development server ◈ Static server listening to 88888 @@ -197,7 +197,7 @@ exports[`frameworks/framework-detection > should warn if using static server and ◈ 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\\" +◈ Running static server from \\"should-warn-if-using-static-server-and-target-port-is-configured/public\\" ◈ Setting up local development server ◈ Static server listening to 88888