-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make expectSnapshot available in all functional test runs #82932
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6e95ee7
Make expectSnapshot available in all functional test runs
dgieselaar 7cee115
Add & update tests
dgieselaar 3bb35e5
Merge branch 'master' of github.com:elastic/kibana into snapshot-test…
dgieselaar 8f24c32
Make sure unused snapshot check only runs once
dgieselaar 2076517
Merge branch 'master' of github.com:elastic/kibana into snapshot-test…
dgieselaar f6f84b5
Remove console.log statement
dgieselaar 7105392
Fix failing test
dgieselaar 5d9e332
Merge branch 'master' of github.com:elastic/kibana into snapshot-test…
dgieselaar feb156a
Define own Mocha types to prevent Jest conflicts
dgieselaar c88ce41
Merge branch 'master' of github.com:elastic/kibana into snapshot-test…
dgieselaar 61ed37b
Move snapshot typings file to test/typings
dgieselaar 56f0c9b
Merge branch 'master' of github.com:elastic/kibana into snapshot-test…
dgieselaar 22bd132
Add -u shorthand option for updating baseline screenshots and snapshots
dgieselaar 4342dd6
move types
dgieselaar 779ab6b
Use existing fake mocha types
dgieselaar a12d3ea
Remove unused type import
dgieselaar 148982d
Fix type errors
dgieselaar af9e222
Merge branch 'master' of github.com:elastic/kibana into pr/82932
spalger 2825618
unify global ftr types under kbn-test
spalger 78e261a
remove unnecessary arrow -> function convert
spalger c8583e7
avoid using typescript specific import paths
spalger 0ef5514
Merge branch 'master' of github.com:elastic/kibana into pr/82932
spalger d7e295d
don't import ftr globals in kbn-test package
spalger 610387f
include the files in ftr projects so that project check associates th…
spalger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
packages/kbn-test/src/functional_test_runner/lib/snapshots/decorate_snapshot_ui.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Test } from './mocha_types'; | ||
import { Lifecycle } from '../lifecycle'; | ||
import { decorateSnapshotUi, expectSnapshot } from './decorate_snapshot_ui'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
|
||
describe('decorateSnapshotUi', () => { | ||
describe('when running a test', () => { | ||
let lifecycle: Lifecycle; | ||
beforeEach(() => { | ||
lifecycle = new Lifecycle(); | ||
decorateSnapshotUi(lifecycle, false); | ||
}); | ||
|
||
it('passes when the snapshot matches the actual value', async () => { | ||
const test: Test = { | ||
title: 'Test', | ||
file: 'foo.ts', | ||
parent: { | ||
file: 'foo.ts', | ||
tests: [], | ||
suites: [], | ||
}, | ||
} as any; | ||
|
||
await lifecycle.beforeEachTest.trigger(test); | ||
|
||
expect(() => { | ||
expectSnapshot('foo').toMatchInline(`"foo"`); | ||
}).not.toThrow(); | ||
}); | ||
|
||
it('throws when the snapshot does not match the actual value', async () => { | ||
const test: Test = { | ||
title: 'Test', | ||
file: 'foo.ts', | ||
parent: { | ||
file: 'foo.ts', | ||
tests: [], | ||
suites: [], | ||
}, | ||
} as any; | ||
|
||
await lifecycle.beforeEachTest.trigger(test); | ||
|
||
expect(() => { | ||
expectSnapshot('foo').toMatchInline(`"bar"`); | ||
}).toThrow(); | ||
}); | ||
|
||
it('writes a snapshot to an external file if it does not exist', async () => { | ||
const test: Test = { | ||
title: 'Test', | ||
file: __filename, | ||
isPassed: () => true, | ||
} as any; | ||
|
||
// @ts-expect-error | ||
test.parent = { | ||
file: __filename, | ||
tests: [test], | ||
suites: [], | ||
}; | ||
|
||
await lifecycle.beforeEachTest.trigger(test); | ||
|
||
const snapshotFile = path.resolve( | ||
__dirname, | ||
'__snapshots__', | ||
'decorate_snapshot_ui.test.snap' | ||
); | ||
|
||
expect(fs.existsSync(snapshotFile)).toBe(false); | ||
|
||
expect(() => { | ||
expectSnapshot('foo').toMatch(); | ||
}).not.toThrow(); | ||
|
||
await lifecycle.afterTestSuite.trigger(test.parent); | ||
|
||
expect(fs.existsSync(snapshotFile)).toBe(true); | ||
|
||
fs.unlinkSync(snapshotFile); | ||
|
||
fs.rmdirSync(path.resolve(__dirname, '__snapshots__')); | ||
}); | ||
}); | ||
|
||
describe('when updating snapshots', () => { | ||
let lifecycle: Lifecycle; | ||
beforeEach(() => { | ||
lifecycle = new Lifecycle(); | ||
decorateSnapshotUi(lifecycle, true); | ||
}); | ||
|
||
it("doesn't throw if the value does not match", async () => { | ||
const test: Test = { | ||
title: 'Test', | ||
file: 'foo.ts', | ||
parent: { | ||
file: 'foo.ts', | ||
tests: [], | ||
suites: [], | ||
}, | ||
} as any; | ||
|
||
await lifecycle.beforeEachTest.trigger(test); | ||
|
||
expect(() => { | ||
expectSnapshot('bar').toMatchInline(`"foo"`); | ||
}).not.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I definitely reached for the
-u
flag here, maybe it would be nice to have an--update,-u
flag that sets bothupdateBaselines
andupdateSnapshots
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done - I tried to add
-u
only where necessary, but let me know if I missed anything.