Skip to content

Commit

Permalink
test: Cache Babel output (#5539)
Browse files Browse the repository at this point in the history
This caches Babel's transpiler output for reuse, and should speed up all
test runs in theory, but the effect is most noticeable on local test
runs.

This uses a fork of karma-babel-preprocessor, which contains
babel/karma-babel-preprocessor#77. If/when that
PR is merged, we can move back to the upstream module.

Local runs will start faster because only modified source files will be
re-processed through Babel when the tests start up.

In the Selenium workflow, Babel output and node_modules will both be
computed by the singular build-shaka job, stored, and then reused by all
the Selenium lab matrix jobs.

On my workstation (3.3 GHz cores, 32GB RAM, spinning platter disk), I
see tests start about ~60 seconds faster. In the lab (2.1-4.7 GHz cores,
64GB RAM, solid-state disk), I see tests start about ~10 seconds faster.
  • Loading branch information
joeyparrish committed Aug 30, 2023
1 parent 5e133d0 commit 6ec0450
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 21 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/selenium-lab-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,30 @@ jobs:
- name: Build Player
run: python3 build/all.py

- name: Preprocess with Babel
run: |
# Run the test preprocessor without running the actual tests.
# This lets us cache Babel's output and run it only once.
# Ignore the exit code, since you get an error code if the filter
# excludes all tests.
./build/test.py \
--use-xvfb --browsers Chrome \
--filter ThisFilterMatchesNoTests || true
- name: Cache dependencies
uses: actions/cache@v3
id: npm-cache
with:
path: node_modules/
key: node-${{ hashFiles('package-lock.json') }}

- name: Cache Babel output
uses: actions/cache@v3
id: babel-cache
with:
path: .babel-cache
key: babel-${{ hashFiles('*.js', 'demo/**.js', 'lib/**.js', 'ui/**.js', 'test/**.js', 'third_party/**.js') }}

- name: Store Player build
uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -206,6 +230,17 @@ jobs:
with:
path: node_modules/
key: node-${{ hashFiles('package-lock.json') }}
fail-on-cache-miss: true # Cached by the build-shaka job above
enableCrossOsArchive: true # Share archives from Linux to Windows

- name: Cache Babel output
uses: actions/cache@v3
id: babel-cache
with:
path: .babel-cache
key: babel-${{ hashFiles('*.js', 'demo/**.js', 'lib/**.js', 'ui/**.js', 'test/**.js', 'third_party/**.js') }}
fail-on-cache-miss: true # Cached by the build-shaka job above
enableCrossOsArchive: true # Share archives from Linux to Windows

- name: Install dependencies
if: steps.npm-cache.outputs.cache-hit != 'true'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docs/api/
coverage/
.DS_Store
.vscode
.babel-cache
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ module.exports = (config) => {
},

babelPreprocessor: {
// Cache results in .babel-cache
cachePath: '.babel-cache',
options: {
presets: ['@babel/preset-env'],
// Add source maps so that backtraces refer to the original code.
Expand Down
226 changes: 206 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@babel/core": "^7.17.5",
"@babel/polyfill": "^7.12.1",
"@babel/preset-env": "^7.16.11",
"@joeyparrish/karma-babel-preprocessor": "^8.2.0",
"@teppeis/clutz": "^1.0.29-4c95e12.v20190929",
"awesomplete": "^1.1.5",
"babel-plugin-istanbul": "^6.1.1",
Expand All @@ -38,7 +39,6 @@
"js-yaml": "^4.1.0",
"jsdoc": "github:joeyparrish/jsdoc#2ca85bb6",
"karma": "^6.3.16",
"karma-babel-preprocessor": "^8.0.2",
"karma-coverage": "^2.2.0",
"karma-jasmine": "^4.0.1",
"karma-jasmine-ajax": "^0.1.13",
Expand Down

0 comments on commit 6ec0450

Please sign in to comment.