|
1 | 1 | import { buildSchema, buildASTSchema } from 'graphql'; |
2 | 2 | import path from 'path'; |
| 3 | +import { vi } from 'vitest'; |
3 | 4 | import { TempDir } from './utils/temp-dir'; |
4 | 5 | import { runTests } from './utils/runner'; |
5 | 6 | import { loadConfig, loadConfigSync, ConfigNotFoundError, GraphQLConfig } from 'graphql-config'; |
@@ -275,6 +276,70 @@ runTests({ async: loadConfig, sync: loadConfigSync })((load, mode) => { |
275 | 276 | expect(config.getProjectForFile('./foo/ignored/component.ts').name).toBe('bar'); |
276 | 277 | }); |
277 | 278 |
|
| 279 | + test.each(['loadDocumentsSync', 'loadDocuments'] as const)('%s uses exclude', async (method) => { |
| 280 | + temp.createFile( |
| 281 | + '.graphqlrc', |
| 282 | + ` |
| 283 | + projects: |
| 284 | + foo: |
| 285 | + schema: ./foo.graphql |
| 286 | + include: ./foo/*.ts |
| 287 | + exclude: ./foo/ignored/** |
| 288 | + `, |
| 289 | + ); |
| 290 | + |
| 291 | + const config = await load({ rootDir: temp.dir }); |
| 292 | + |
| 293 | + const project = config.getProject('foo'); |
| 294 | + |
| 295 | + const loadDocumentsSyncSpy = vi |
| 296 | + .spyOn(project['_extensionsRegistry'].loaders.documents, method) |
| 297 | + .mockReturnValue([]); |
| 298 | + |
| 299 | + await project[method]('./**/*'); |
| 300 | + |
| 301 | + expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*', { |
| 302 | + ignore: './foo/ignored/**', |
| 303 | + }); |
| 304 | + |
| 305 | + loadDocumentsSyncSpy.mockRestore(); |
| 306 | + }); |
| 307 | + |
| 308 | + test.each(['loadDocumentsSync', 'loadDocuments'] as const)( |
| 309 | + '%s respects options.ignore when provided (overrides exclude)', |
| 310 | + async (method) => { |
| 311 | + temp.createFile('schema.graphql', testSDL); |
| 312 | + |
| 313 | + temp.createFile( |
| 314 | + '.graphqlrc', |
| 315 | + ` |
| 316 | + schema: ./schema.graphql |
| 317 | + documents: ./**/*.graphql |
| 318 | + exclude: |
| 319 | + - "**/excluded/**" |
| 320 | + `, |
| 321 | + ); |
| 322 | + |
| 323 | + const config = await load({ rootDir: temp.dir }); |
| 324 | + const project = config.getDefault(); |
| 325 | + |
| 326 | + // Create a spy on the internal method and mock its return value |
| 327 | + const loadDocumentsSyncSpy = vi |
| 328 | + .spyOn(project['_extensionsRegistry'].loaders.documents, method) |
| 329 | + .mockReturnValue([]); |
| 330 | + |
| 331 | + // Call with custom ignore - should override exclude |
| 332 | + await project[method]('./**/*.graphql', { ignore: '**/custom-ignored/**' }); |
| 333 | + |
| 334 | + // Verify it was called with custom ignore (NOT the exclude from config) |
| 335 | + expect(loadDocumentsSyncSpy).toHaveBeenCalledWith('./**/*.graphql', { |
| 336 | + ignore: '**/custom-ignored/**', |
| 337 | + }); |
| 338 | + |
| 339 | + loadDocumentsSyncSpy.mockRestore(); |
| 340 | + }, |
| 341 | + ); |
| 342 | + |
278 | 343 | test('customizable config name', async () => { |
279 | 344 | temp.createFile(schemaFilename, testSDL); |
280 | 345 | temp.createFile('foo.config.js', `module.exports = { schema: '${schemaFilename}' }`); |
|
0 commit comments