Skip to content

Commit 568e26c

Browse files
jayaddisonpicnixz
andauthored
[tests] JavaScript: refactor test fixtures (#12102)
This PR allows to serve JavaScript test fixtures using a fixture-based logic as for Python tests. Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 4fbd368 commit 568e26c

File tree

18 files changed

+177
-40
lines changed

18 files changed

+177
-40
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ doc/_build/
3131
doc/locale/
3232
tests/.coverage
3333
tests/build/
34+
tests/js/roots/*/_build
3435
tests/test-server.lock
3536
utils/regression_test.js
3637

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ output-format = "full"
44

55
extend-exclude = [
66
"tests/roots/*",
7+
"tests/js/roots/*",
78
"build/*",
89
"doc/_build/*",
910
"sphinx/search/*",

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Bugs fixed
4949
Testing
5050
-------
5151

52+
* karma: refactor HTML search tests to use fixtures generated by Sphinx.
53+
Patch by James Addison.
54+
5255
Release 7.3.7 (released Apr 19, 2024)
5356
=====================================
5457

doc/internals/contributing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,9 @@ Debugging tips
338338
Minified files in ``sphinx/search/minified-js/*.js`` are generated from
339339
non-minified ones using ``uglifyjs`` (installed via npm), with ``-m``
340340
option to enable mangling.
341+
342+
* The ``searchindex.js`` files found in the ``tests/js/fixtures/*`` directories
343+
are generated by using the standard Sphinx HTML builder on the corresponding
344+
input projects found in ``tests/js/roots/*``. The fixtures provide test data
345+
used by the Sphinx JavaScript unit tests, and can be regenerated by running
346+
the ``utils/generate_js_fixtures.py`` script.

karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ module.exports = function(config) {
1515

1616
// list of files / patterns to load in the browser
1717
files: [
18+
{ pattern: 'tests/js/fixtures/**/*.js', included: false, served: true },
1819
'tests/js/documentation_options.js',
20+
'tests/js/language_data.js',
1921
'sphinx/themes/basic/static/doctools.js',
2022
'sphinx/themes/basic/static/searchtools.js',
2123
'sphinx/themes/basic/static/sphinx_highlight.js',

tests/js/fixtures/cpp/searchindex.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/js/fixtures/multiterm/searchindex.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/js/fixtures/partial/searchindex.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/js/language_data.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* language_data.js
3+
* ~~~~~~~~~~~~~~~~
4+
*
5+
* This script contains the language-specific data used by searchtools.js,
6+
* namely the list of stopwords, stemmer, scorer and splitter.
7+
*
8+
* :copyright: Copyright 2007-2024 by the Sphinx team, see AUTHORS.
9+
* :license: BSD, see LICENSE for details.
10+
*
11+
*/
12+
13+
var stopwords = [];
14+
15+
16+
/* Non-minified version is copied as a separate JS file, if available */
17+
18+
/**
19+
* Dummy stemmer for languages without stemming rules.
20+
*/
21+
var Stemmer = function() {
22+
this.stemWord = function(w) {
23+
return w;
24+
}
25+
}
26+

tests/js/roots/cpp/conf.py

Whitespace-only changes.

0 commit comments

Comments
 (0)