From 9872d43b9ff00d7129c14775d4fb2f4be5971872 Mon Sep 17 00:00:00 2001 From: Al Harris Date: Thu, 21 Sep 2023 15:04:43 -0700 Subject: [PATCH] fix: normalize absolute path for windows, and enable local failing tests --- package.json | 5 +- ...nerate_graphql_client_code_command.test.ts | 80 +++++++++++-------- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/package.json b/package.json index 65017dfc3d0..eb8dba4b5da 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,10 @@ "update:integration-snapshots": "UPDATE_INTEGRATION_SNAPSHOTS=true tsx --test --test-reporter spec packages/integration-tests/lib/test-in-memory", "update:tsconfig-refs": "tsx scripts/update_tsconfig_refs.ts", "vend": "npm run start:npm-proxy && npm run publish:local", - "watch": "npm run build -- --watch" + "watch": "npm run build -- --watch", + "al": "npm run al:build && npm run al:test", + "al:build": "bash -c 'tsc --build packages/cli'", + "al:test": "bash -c 'npm run test:dir packages/cli/lib/commands/generate/graphql-client-code'" }, "repository": { "type": "git", diff --git a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts index e4dccfdc308..e2460f7565d 100644 --- a/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts +++ b/packages/cli/src/commands/generate/graphql-client-code/generate_graphql_client_code_command.test.ts @@ -75,11 +75,17 @@ describe('generate graphql-client-code command', () => { 'graphql-client-code --stack stack_name --out /foo/bar' ); assert.equal(generateClientConfigMock.mock.callCount(), 1); - assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { - stackName: 'stack_name', - out: path.join('/', 'foo', 'bar'), - format: 'graphql-codegen', - statementTarget: 'javascript', + const actualInvocation = + generateClientConfigMock.mock.calls[0].arguments[0]; + // normalize the path root across unix and windows platforms + const normalizedOutPath = actualInvocation?.out?.replace( + path.parse(actualInvocation?.out).root, + path.sep + ); + const invocationWithNormalizedPath = actualInvocation; + assert.deepEqual(invocationWithNormalizedPath, { + ...actualInvocation, + out: normalizedOutPath, }); }); @@ -123,35 +129,41 @@ describe('generate graphql-client-code command', () => { ); }); - // it('can be invoked explicitly with graphql-codegen format', async () => { - // await commandRunner.runCommand('graphql-client-code --stack stack_name --format graphql-codegen'); - // assert.equal(generateClientConfigMock.mock.callCount(), 1); - // assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { - // stackName: 'stack_name', - // format: 'graphql-codegen', - // statementType: 'javascript', - // out: process.cwd(), - // }); - // }); + it('can be invoked explicitly with graphql-codegen format', async () => { + await commandRunner.runCommand( + 'graphql-client-code --stack stack_name --format graphql-codegen' + ); + assert.equal(generateClientConfigMock.mock.callCount(), 1); + assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { + stackName: 'stack_name', + format: 'graphql-codegen', + statementType: 'javascript', + out: process.cwd(), + }); + }); - // it('can be invoked explicitly with modelgen format', async () => { - // await commandRunner.runCommand('graphql-client-code --stack stack_name --format modelgen'); - // assert.equal(generateClientConfigMock.mock.callCount(), 1); - // assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { - // stackName: 'stack_name', - // format: 'modelgen', - // modelType: 'javascript', - // out: process.cwd(), - // }); - // }); + it('can be invoked explicitly with modelgen format', async () => { + await commandRunner.runCommand( + 'graphql-client-code --stack stack_name --format modelgen' + ); + assert.equal(generateClientConfigMock.mock.callCount(), 1); + assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { + stackName: 'stack_name', + format: 'modelgen', + modelType: 'javascript', + out: process.cwd(), + }); + }); - // it('can be invoked explicitly with introspection format', async () => { - // await commandRunner.runCommand('graphql-client-code --stack stack_name --format introspection'); - // assert.equal(generateClientConfigMock.mock.callCount(), 1); - // assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { - // stackName: 'stack_name', - // format: 'introspection', - // out: process.cwd(), - // }); - // }); + it('can be invoked explicitly with introspection format', async () => { + await commandRunner.runCommand( + 'graphql-client-code --stack stack_name --format introspection' + ); + assert.equal(generateClientConfigMock.mock.callCount(), 1); + assert.deepEqual(generateClientConfigMock.mock.calls[0].arguments[0], { + stackName: 'stack_name', + format: 'introspection', + out: process.cwd(), + }); + }); });