Skip to content

Commit

Permalink
Merge branch 'v5-candidate' into feature/add-series-tree-shakable
Browse files Browse the repository at this point in the history
  • Loading branch information
illetid committed Nov 8, 2024
2 parents 1258a4b + ceeb359 commit 140a653
Show file tree
Hide file tree
Showing 10 changed files with 324 additions and 121 deletions.
47 changes: 47 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

version: 2.1

parameters:
run_branch_specific_graphics_tests:
type: boolean
default: false

aliases:
- &restore-node-modules-cache
name: Restore node_modules cache
Expand Down Expand Up @@ -65,6 +70,9 @@ commands:
default: false
grep:
type: string
branchSpecificTest:
type: boolean
default: false
steps:
- checkout-with-deps
- run:
Expand All @@ -77,6 +85,7 @@ commands:
echo 'export PRODUCTION_BUILD=<< parameters.productionBuild >>' >> $BASH_ENV
echo 'export GREP="<< parameters.grep >>"' >> $BASH_ENV
echo 'export COMPARE_BRANCH="v5-candidate"' >> $BASH_ENV
echo 'export BRANCH_SPECIFIC_TEST=<< parameters.branchSpecificTest >>' >> $BASH_ENV
- run:
command: scripts/run-graphics-tests.sh
no_output_timeout: 20m
Expand Down Expand Up @@ -206,12 +215,16 @@ jobs:
productionBuild:
type: boolean
default: false
branchSpecificTest:
type: boolean
default: false
executor: node-browsers-executor
steps:
- run-graphics-tests:
devicePixelRatio: << parameters.dpr >>
grep: << parameters.grep >>
productionBuild: << parameters.productionBuild >>
branchSpecificTest: << parameters.branchSpecificTest >>

memleaks-tests:
executor: node-browsers-executor
Expand Down Expand Up @@ -318,7 +331,41 @@ anchors:
workflows:
version: 2

branch-specific-graphics-tests:
when: << pipeline.parameters.run_branch_specific_graphics_tests >>
jobs:
- install-deps:
filters: *default-filters
- install-deps-website:
filters: *default-filters
- build:
filters: *default-filters
requires:
- install-deps
- install-deps-website

- graphics-tests:
name: branch_specific_graphics-tests-part1-dpr<< matrix.dpr >><<# matrix.productionBuild >>-PROD<</ matrix.productionBuild >>
grep: "(api/|applying-options/|series-markers/|price-scale/)"
branchSpecificTest: true
matrix: *graphics-test-matrix
<<: *graphics-test-config
- graphics-tests:
name: branch_specific_graphics-tests-part2-dpr<< matrix.dpr >><<# matrix.productionBuild >>-PROD<</ matrix.productionBuild >>
grep: "(initial-options/|logical-range/|panes/|plugins/|two-scales/|test-cases/)"
branchSpecificTest: true
matrix: *graphics-test-matrix
<<: *graphics-test-config
- graphics-tests:
name: branch_specific_graphics-tests-part3-dpr<< matrix.dpr >><<# matrix.productionBuild >>-PROD<</ matrix.productionBuild >>
grep: "(series/|time-scale/|degenerative-horizontal-series-with-integer-min-tick/)"
branchSpecificTest: true
matrix: *graphics-test-matrix
<<: *graphics-test-config

build-lint-test:
when:
not: << pipeline.parameters.run_branch_specific_graphics_tests >>
jobs:
- install-deps:
filters: *default-filters
Expand Down
9 changes: 9 additions & 0 deletions scripts/run-graphics-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ fi

npm install
npm run $BUILD_SCRIPT
# Remove existing merge-base-dist if it exists
rm -rf ./merge-base-dist
mv ./dist ./merge-base-dist

if [ "$BRANCH_SPECIFIC_TEST" = "true" ]; then
echo "Using BRANCH_SPECIFIC_TEST"
echo "Running generate-golden-content"
npx esno ./tests/e2e/graphics/generate-golden-content.ts ./golden_test_files
export GOLDEN_TEST_CONTENT_PATH="./golden_test_files"
fi

echo "Checkout to HEAD back and build..."

git checkout $HEAD_SHA1
Expand Down
17 changes: 17 additions & 0 deletions tests/e2e/graphics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ npx esno ./runner.ts ./path/to/golden/standalone/module.js ./path/to/test/standa
Each path to the standalone module might be either to a local file (relative/absolute path to a file) or remote file (via http/https).
If file is local then local server will be runner to serve that file (see [serve-local-files.ts](../serve-local-files.ts) module).

## Branch-Specific Test Cases

By default, the test runner uses the current branch's test case code for both golden and test builds of the library. However, you can configure the test runner to use test case code from different branches:

### Using Golden Branch Test Cases

To use test case code from the golden branch for the golden build (useful when testing API syntax changes):

1. Use the `scripts/run-graphics-tests.sh` script
2. Set the environment variable `BRANCH_SPECIFIC_TEST="true"`

Example:

```bash
BRANCH_SPECIFIC_TEST="true" ./scripts/run-graphics-tests.sh
```

## Tips

1. By default for each test case golden, test and diff screenshots will be written to a `.gendata` folder (can be changed via `CMP_OUT_DIR` env variable).
Expand Down
48 changes: 48 additions & 0 deletions tests/e2e/graphics/generate-golden-content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as fs from 'node:fs';
import * as path from 'node:path';

import { generatePageContent } from './generate-test-cases';
import { getTestCases, TestCase } from './helpers/get-test-cases';
import { rmRf } from './utils';

if (process.argv.length < 3) {
console.log(
'Usage: generate-golden-content GOLDEN_OUTPUT_PATH'
);
process.exit(1);
}

const args = process.argv.slice(2);
const goldenOutputPath = args[0];

const buildMode =
process.env.PRODUCTION_BUILD === 'true' ? 'production' : 'development';

const testCases = getTestCases();

rmRf(goldenOutputPath);
fs.mkdirSync(goldenOutputPath, { recursive: true });

for (const groupName of Object.keys(testCases)) {
generateTestCases(testCases[groupName]);
}

function generateTestCases(groupTestCases: TestCase[]): void {
for (const testCase of groupTestCases) {
const testCaseOutDir = path.join(goldenOutputPath, testCase.name);
rmRf(testCaseOutDir);
fs.mkdirSync(testCaseOutDir, { recursive: true });
path.join(testCaseOutDir, 'test-content.html');

const goldenPageContent = generatePageContent(
'',
testCase.caseContent,
buildMode
);

fs.writeFileSync(
path.join(testCaseOutDir, 'test-content.html'),
goldenPageContent
);
}
}
36 changes: 36 additions & 0 deletions tests/e2e/graphics/generate-test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { fileURLToPath } from 'node:url';

const currentFilePath = fileURLToPath(import.meta.url);
const currentDirectory = path.dirname(currentFilePath);

const dummyContent = fs.readFileSync(
path.join(currentDirectory, 'helpers', 'test-page-dummy.html'),
{ encoding: 'utf-8' }
);
const resizeObserverPolyfill =
fs
.readFileSync(
path.join(
currentDirectory,
...'../../../node_modules/@juggle/resize-observer/lib/exports/resize-observer.umd.js'.split(
'/'
)
),
{ encoding: 'utf-8' }
)
.replace(/global\.ResizeObserver/g, 'global.ResizeObserverPolyfill') +
'; window.ResizeObserver = window.ResizeObserverPolyfill.ResizeObserver';

export function generatePageContent(
standaloneBundlePath: string,
testCaseCode: string,
buildMode: 'production' | 'development'
): string {
return dummyContent
.replace('//RESIZE_OBSERVER_POLYFILL', resizeObserverPolyfill)
.replace('PATH_TO_STANDALONE_MODULE', standaloneBundlePath || 'PATH_TO_STANDALONE_MODULE') // keep string if using BRANCH_SPECIFIC_TEST
.replace('TEST_CASE_SCRIPT', testCaseCode)
.replace('{BUILD_MODE}', buildMode);
}
Loading

0 comments on commit 140a653

Please sign in to comment.