Skip to content

Commit

Permalink
add bail test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Mar 11, 2024
1 parent 66d7cfd commit 0868d6c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/example-tada/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,10 @@ const introspection = {
{
"kind": "SCALAR",
"name": "Boolean"
},
{
"kind": "SCALAR",
"name": "Any"
}
],
"directives": []
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/fixture-project-unused-fields/fixtures/bail.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as React from 'react';
import { useQuery } from 'urql';
import { graphql } from './gql';
// @ts-expect-error
import { Pokemon } from './fragment';

const PokemonQuery = graphql(`
query Po($id: ID!) {
pokemon(id: $id) {
id
fleeRate
...pokemonFields
attacks {
special {
name
damage
}
}
weight {
minimum
maximum
}
name
__typename
}
}
`);

const Pokemons = () => {
const [result] = useQuery({
query: PokemonQuery,
variables: { id: '' }
});

const pokemon = React.useMemo(() => result.data?.pokemon, [])

// @ts-expect-error
return <Pokemon data={result.data?.pokemon} />;
}

44 changes: 44 additions & 0 deletions test/e2e/unused-fieds.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('unused fields', () => {
'immediate-destructuring.tsx'
);
const outfileDestructuring = path.join(projectPath, 'destructuring.tsx');
const outfileBail = path.join(projectPath, 'bail.tsx');
const outfileFragmentDestructuring = path.join(
projectPath,
'fragment-destructuring.tsx'
Expand All @@ -30,6 +31,11 @@ describe('unused fields', () => {
fileContent: '// empty',
scriptKindName: 'TS',
} satisfies ts.server.protocol.OpenRequestArgs);
server.sendCommand('open', {
file: outfileBail,
fileContent: '// empty',
scriptKindName: 'TS',
} satisfies ts.server.protocol.OpenRequestArgs);
server.sendCommand('open', {
file: outfileFragment,
fileContent: '// empty',
Expand Down Expand Up @@ -60,6 +66,13 @@ describe('unused fields', () => {
'utf-8'
),
},
{
file: outfileBail,
fileContent: fs.readFileSync(
path.join(projectPath, 'fixtures/bail.tsx'),
'utf-8'
),
},
{
file: outfileFragment,
fileContent: fs.readFileSync(
Expand Down Expand Up @@ -111,6 +124,10 @@ describe('unused fields', () => {
file: outfileDestructuringFromStart,
tmpfile: outfileDestructuringFromStart,
} satisfies ts.server.protocol.SavetoRequestArgs);
server.sendCommand('saveto', {
file: outfileBail,
tmpfile: outfileBail,
} satisfies ts.server.protocol.SavetoRequestArgs);
});

afterAll(() => {
Expand All @@ -120,6 +137,7 @@ describe('unused fields', () => {
fs.unlinkSync(outfilePropAccess);
fs.unlinkSync(outfileFragmentDestructuring);
fs.unlinkSync(outfileDestructuringFromStart);
fs.unlinkSync(outfileBail);
} catch {}
});

Expand Down Expand Up @@ -361,4 +379,30 @@ describe('unused fields', () => {
]
`);
}, 30000);

it('Bails unused fields when memo func is used', async () => {
const res = server.responses.filter(
resp =>
resp.type === 'event' &&
resp.event === 'semanticDiag' &&
resp.body?.file === outfileBail
);
expect(res[0].body.diagnostics).toMatchInlineSnapshot(`
[
{
"category": "error",
"code": 2578,
"end": {
"line": 4,
"offset": 20,
},
"start": {
"line": 4,
"offset": 1,
},
"text": "Unused '@ts-expect-error' directive.",
},
]
`);
}, 30000);
});

0 comments on commit 0868d6c

Please sign in to comment.