From 609d286a0b845fb363a4ade9bbbfb70fd298a10a Mon Sep 17 00:00:00 2001 From: Jason Kuhrt Date: Wed, 18 Dec 2024 13:25:45 -0500 Subject: [PATCH] refactor --- integration-tests/testkit/fs.ts | 17 ++++++++ integration-tests/tests/cli/dev.spec.ts | 57 +++++++------------------ 2 files changed, 32 insertions(+), 42 deletions(-) create mode 100644 integration-tests/testkit/fs.ts diff --git a/integration-tests/testkit/fs.ts b/integration-tests/testkit/fs.ts new file mode 100644 index 0000000000..18b2c9a12c --- /dev/null +++ b/integration-tests/testkit/fs.ts @@ -0,0 +1,17 @@ +import { randomUUID } from 'node:crypto'; +import { readFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; + +export function tmpFile(extension: string) { + const dir = tmpdir(); + const fileName = randomUUID(); + const filepath = join(dir, `${fileName}.${extension}`); + + return { + filepath, + read() { + return readFile(filepath, 'utf-8'); + }, + }; +} diff --git a/integration-tests/tests/cli/dev.spec.ts b/integration-tests/tests/cli/dev.spec.ts index 36d3a81a1f..65fc23c9a8 100644 --- a/integration-tests/tests/cli/dev.spec.ts +++ b/integration-tests/tests/cli/dev.spec.ts @@ -1,11 +1,5 @@ /* eslint-disable no-process-env */ -import { randomUUID } from 'node:crypto'; -import { readFile } from 'node:fs/promises'; -import { tmpdir } from 'node:os'; -import { join } from 'node:path'; -import { ProjectType } from 'testkit/gql/graphql'; -import { createCLI } from '../../testkit/cli'; -import { initSeed } from '../../testkit/seed'; +import { tmpFile } from '../../testkit/fs'; import { test } from '../../testkit/test'; describe('dev', () => { @@ -124,18 +118,14 @@ describe('dev --remote', () => { await expect(supergraph.read()).resolves.toMatch('http://localhost/bar'); }); - test('uses latest composable version by default', async () => { - const { createOrg } = await initSeed().createOwner(); - const { createProject, setFeatureFlag } = await createOrg(); - const { createTargetAccessToken, setNativeFederation } = await createProject( - ProjectType.Federation, - ); - const { secret } = await createTargetAccessToken({}); - const cli = createCLI({ readwrite: secret, readonly: secret }); - + test.only('uses latest composable version by default', async ({ + org, + projectFederation: project, + cliFederation: cli, + }) => { // Once we ship native federation v2 composition by default, we can remove these two lines - await setFeatureFlag('compareToPreviousComposableVersion', true); - await setNativeFederation(true); + await org.setFeatureFlag('compareToPreviousComposableVersion', true); + await project.setNativeFederation(true); await cli.publish({ sdl: /* GraphQL */ ` @@ -204,18 +194,14 @@ describe('dev --remote', () => { expect(content).toMatch('http://localhost/baz'); }); - test('uses latest version when requested', async () => { - const { createOrg } = await initSeed().createOwner(); - const { createProject, setFeatureFlag } = await createOrg(); - const { createTargetAccessToken, setNativeFederation } = await createProject( - ProjectType.Federation, - ); - const { secret } = await createTargetAccessToken({}); - const cli = createCLI({ readwrite: secret, readonly: secret }); - + test('uses latest version when requested', async ({ + org, + projectFederation: project, + cliFederation: cli, + }) => { // Once we ship native federation v2 composition by default, we can remove these two lines - await setFeatureFlag('compareToPreviousComposableVersion', true); - await setNativeFederation(true); + await org.setFeatureFlag('compareToPreviousComposableVersion', true); + await project.setNativeFederation(true); await cli.publish({ sdl: /* GraphQL */ ` @@ -283,16 +269,3 @@ describe('dev --remote', () => { await expect(cmd).rejects.toThrowError('Non-shareable field'); }); }); - -function tmpFile(extension: string) { - const dir = tmpdir(); - const fileName = randomUUID(); - const filepath = join(dir, `${fileName}.${extension}`); - - return { - filepath, - read() { - return readFile(filepath, 'utf-8'); - }, - }; -}