Skip to content

Commit

Permalink
tests: add test cases for gts and gjs files
Browse files Browse the repository at this point in the history
  • Loading branch information
DeclanBoller committed Sep 16, 2024
1 parent b48ffab commit aeba914
Show file tree
Hide file tree
Showing 3 changed files with 463 additions and 35 deletions.
2 changes: 2 additions & 0 deletions packages/graphql-tag-pluck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@
"@babel/parser": "7.25.6",
"@babel/traverse": "7.25.6",
"@babel/types": "7.25.6",
"@glimmer/syntax": "^0.92.3",
"@types/babel__traverse": "7.20.6",
"@vue/compiler-sfc": "3.5.6",
"astrojs-compiler-sync": "^1.0.0",
"glint": "^0.0.25",
"svelte": "4.2.19",
"svelte2tsx": "0.7.19"
},
Expand Down
213 changes: 213 additions & 0 deletions packages/graphql-tag-pluck/tests/graphql-tag-pluck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2393,5 +2393,218 @@ describe('graphql-tag-pluck', () => {
'query queryName { id }\n#EXPRESSION:ANOTHER_VARIABLE',
);
});

it('should pluck graphql-tag template literals from .gts file', async () => {
const sources = await pluck(
'tmp-XXXXXX.gts',
freeText(`
import gql from 'graphql-tag';
const query = gql\`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
\`;
export default class ExampleComponent extends Component {}
`),
);

expect(sources.map(source => source.body).join('\n\n')).toEqual(
freeText(`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
`),
);
});

it('should pluck graphql-tag template literals from .gjs file', async () => {
const sources = await pluck(
'tmp-XXXXXX.gjs',
freeText(`
import gql from 'graphql-tag';
const query = gql\`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
\`;
export default class ExampleComponent extends Component {}
`),
);

expect(sources.map(source => source.body).join('\n\n')).toEqual(
freeText(`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
`),
);
});

it('should pluck graphql-tag template literals from .gts file with 2 queries', async () => {
const sources = await pluck(
'tmp-XXXXXX.gts',
freeText(`
import gql from 'graphql-tag';
const query1 = gql\`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
\`;
const query2 = gql\`
query IndexQuery2 {
site {
siteMetadata {
title
}
}
}
\`;
export default class ExampleComponent extends Component {}
`),
);

expect(sources.map(source => source.body).join('\n\n')).toEqual(
freeText(`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
query IndexQuery2 {
site {
siteMetadata {
title
}
}
}
`),
);
});

it('should pluck graphql-tag template literals from .gts file with multiple script sections', async () => {
const sources = await pluck(
'tmp-XXXXXX.gts',
freeText(`
import Component from '@glimmer/component';
const query1 = gql\`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
\`;
export function anotherQuery() {
const query2 = gql\`
query IndexQuery2 {
site {
siteMetadata {
title
}
}
}
\`;
}
export default class ExampleComponent extends Component {}
`),
);

expect(sources.map(source => source.body).join('\n\n')).toEqual(
freeText(`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
query IndexQuery2 {
site {
siteMetadata {
title
}
}
}
`),
);
});

it('should pluck graphql-tag template literals from .gts file, ignoring comments', async () => {
const sources = await pluck(
'tmp-XXXXXX.gts',
freeText(`
import gql from 'graphql-tag';
const query = gql\`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
\`;
// const query2 = gql\`
// query IndexQuery2 {
// site {
// siteMetadata {
// title
// }
// }
// }
// \`;
export default class ExampleComponent extends Component {}
`),
);

expect(sources.map(source => source.body).join('\n\n')).toEqual(
freeText(`
query IndexQuery {
site {
siteMetadata {
title
}
}
}
`),
);
});
});
});
Loading

0 comments on commit aeba914

Please sign in to comment.