|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import { isScoutTestsOnlyDiff } from './selective_scout'; |
| 11 | + |
| 12 | +describe('isScoutTestsOnlyDiff', () => { |
| 13 | + it('returns false for an empty diff (no signal)', () => { |
| 14 | + expect(isScoutTestsOnlyDiff([])).toBe(false); |
| 15 | + }); |
| 16 | + |
| 17 | + it('returns true for a single Scout UI spec', () => { |
| 18 | + expect( |
| 19 | + isScoutTestsOnlyDiff([ |
| 20 | + 'src/platform/plugins/shared/discover/test/scout/ui/parallel_tests/foo.spec.ts', |
| 21 | + ]) |
| 22 | + ).toBe(true); |
| 23 | + }); |
| 24 | + |
| 25 | + it('returns true for a single Scout API spec', () => { |
| 26 | + expect( |
| 27 | + isScoutTestsOnlyDiff([ |
| 28 | + 'x-pack/platform/plugins/shared/maps/test/scout/api/tests/health.spec.ts', |
| 29 | + ]) |
| 30 | + ).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it('returns true for shared test code (fixtures, page objects) inside a scope', () => { |
| 34 | + expect( |
| 35 | + isScoutTestsOnlyDiff([ |
| 36 | + 'src/platform/plugins/shared/discover/test/scout/ui/fixtures/page_objects/landing.ts', |
| 37 | + 'src/platform/plugins/shared/discover/test/scout/ui/helpers/build_query.ts', |
| 38 | + ]) |
| 39 | + ).toBe(true); |
| 40 | + }); |
| 41 | + |
| 42 | + it('returns true for custom Scout server directories (scout_*)', () => { |
| 43 | + expect( |
| 44 | + isScoutTestsOnlyDiff([ |
| 45 | + 'x-pack/solutions/security/plugins/cloud_security_posture/test/scout_with_setup/ui/tests/findings.spec.ts', |
| 46 | + ]) |
| 47 | + ).toBe(true); |
| 48 | + }); |
| 49 | + |
| 50 | + it('returns true for generated manifests under .meta', () => { |
| 51 | + expect( |
| 52 | + isScoutTestsOnlyDiff([ |
| 53 | + 'src/platform/plugins/shared/discover/test/scout/.meta/ui/configs.json', |
| 54 | + ]) |
| 55 | + ).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it('treats README / *.md / CHANGELOG as noise (still true if every other file is Scout)', () => { |
| 59 | + expect( |
| 60 | + isScoutTestsOnlyDiff([ |
| 61 | + 'README.md', |
| 62 | + 'src/platform/plugins/shared/discover/test/scout/ui/README', |
| 63 | + 'CHANGELOG.asciidoc.md', |
| 64 | + 'src/platform/plugins/shared/discover/test/scout/ui/tests/foo.spec.ts', |
| 65 | + ]) |
| 66 | + ).toBe(true); |
| 67 | + }); |
| 68 | + |
| 69 | + it('returns false when the diff is noise-only (no Scout signal)', () => { |
| 70 | + expect(isScoutTestsOnlyDiff(['README.md', 'docs/extend/scout/best-practices.md'])).toBe(false); |
| 71 | + }); |
| 72 | + |
| 73 | + it('returns false when any non-Scout, non-noise file is present', () => { |
| 74 | + expect( |
| 75 | + isScoutTestsOnlyDiff([ |
| 76 | + 'src/platform/plugins/shared/discover/test/scout/ui/tests/foo.spec.ts', |
| 77 | + 'src/platform/plugins/shared/discover/public/application/main.tsx', |
| 78 | + ]) |
| 79 | + ).toBe(false); |
| 80 | + }); |
| 81 | + |
| 82 | + it('returns false for plugin source changes that are not under a Scout scope', () => { |
| 83 | + expect( |
| 84 | + isScoutTestsOnlyDiff(['src/platform/plugins/shared/discover/public/application/main.tsx']) |
| 85 | + ).toBe(false); |
| 86 | + }); |
| 87 | + |
| 88 | + it('does not confuse `test/scout_<custom>/<not-api-or-ui>` with a Scout scope', () => { |
| 89 | + expect( |
| 90 | + isScoutTestsOnlyDiff([ |
| 91 | + 'src/platform/plugins/shared/discover/test/scout_setup/playwright.config.ts', |
| 92 | + ]) |
| 93 | + ).toBe(false); |
| 94 | + }); |
| 95 | +}); |
0 commit comments