diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fbef947..8e50960 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,4 +24,12 @@ jobs: run: npx playwright install --with-deps - name: Run tests - run: make test \ No newline at end of file + run: make test + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: playwright-report + path: playwright-report/ + retention-days: 7 \ No newline at end of file diff --git a/CLAUDE.md b/CLAUDE.md index 7ba7c6f..83a8f1d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -20,6 +20,10 @@ For comprehensive project information including build commands, architecture det - Tests run in headless Chrome for consistent results across environments - Focus on testing the public API (`Flotr.draw()`) rather than internal implementation +**File Creation Guidelines:** +- CRITICAL: Always create files with Unix line endings (LF), never Windows (CRLF) +- This prevents "required file not found" errors when executing scripts + **Architecture Constraints:** - New chart types must use the `Flotr.addType(name, implementation)` pattern - New plugins must use the `Flotr.addPlugin(name, implementation)` pattern diff --git a/Makefile b/Makefile index 411052e..8f7657c 100644 --- a/Makefile +++ b/Makefile @@ -20,8 +20,11 @@ libraries: $(SMOOSH) ie: $(SMOOSH) $(SMOOSH) make/ie.json -flotr2: libraries ie $(SMOOSH) +build: libraries ie $(SMOOSH) $(SMOOSH) make/flotr2.json + $(SMOOSH) make/examples.json + +flotr2: build cat build/lib.js build/flotr2.js > flotr2.js cat build/lib.min.js > flotr2.min.js cat build/flotr2.min.js >> flotr2.min.js @@ -34,8 +37,7 @@ flotr2-basic: libraries ie $(SMOOSH) cat build/lib.min.js > flotr2-basic.min.js cat build/flotr2-basic.min.js >> flotr2-basic.min.js -flotr-examples: $(SMOOSH) - $(SMOOSH) make/examples.json +flotr2-examples: build cp build/examples.min.js flotr2.examples.min.js cp build/examples-types.js flotr2.examples.types.js diff --git a/examples/examples.css b/examples/examples.css index 08c8fe7..d9df602 100644 --- a/examples/examples.css +++ b/examples/examples.css @@ -4,6 +4,11 @@ body { margin: 0px; } +.CodeMirror { + font-family: 'Courier New', monospace !important; + font-size: 12px; +} + /* Example */ .flotr-example { diff --git a/examples/js/Editor.js b/examples/js/Editor.js index 1781c64..d279572 100644 --- a/examples/js/Editor.js +++ b/examples/js/Editor.js @@ -7,7 +7,6 @@ T_CONTROLS = '
' + - '' + '' + '
', T_EDITOR = '
', @@ -139,9 +138,6 @@ execute(); } - controls.delegate('.fiddle', 'click', function () { - fiddle(); - }); // Error handling: window.onerror = function (message, url, line) { @@ -217,47 +213,6 @@ errors.html(html); } - function fiddle () { - var - url = 'http://jsfiddle.net/api/post/jquery/1.7/', - form = $('
'), - input; - - // Resources - resources = [ - 'https://raw.github.com/HumbleSoftware/Flotr2/main/flotr2.min.js', - 'https://raw.github.com/HumbleSoftware/Flotr2/main/examples/examples.css' - ]; - input = $('') - .attr('value', resources.join(',')); - form.append(input); - - // HTML - input = $('') - .attr('value', '
'); - form.append(input); - - // CSS - input = $('') - form.append(input); - input = $('') - .attr('value', - '#'+renderId+' {\n width: 340px;\n height: 220px;' + - '\n margin: 24px auto;\n}' - ); - form.append(input); - - // JS - input = $('') - .attr('value', '$(function () {\n' + example + '\n});'); - - form.append(input); - - // Submit - form.append(input); - $(document.body).append(form); - form.submit(); - } COUNT++; diff --git a/examples/js/Examples.js b/examples/js/Examples.js index 4614a01..6558e39 100644 --- a/examples/js/Examples.js +++ b/examples/js/Examples.js @@ -69,7 +69,7 @@ Examples.prototype = { "basic-axis", "basic-bars", "basic-bars-horizontal", - "basic-bar-stacked", + "basic-bars-stacked", "basic-stacked-horizontal", "basic-pie", "basic-radar", diff --git a/package.json b/package.json index 1165c12..74206ea 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,10 @@ "lib": "lib" }, "scripts": { - "test": "playwright test", - "test:headed": "playwright test --headed", - "test:debug": "playwright test --debug" + "build": "make build", + "test": "npm run build && playwright test", + "test:headed": "npm run build && playwright test --headed", + "test:debug": "npm run build && playwright test --debug" }, "devDependencies": { "@playwright/test": "^1.40.0", diff --git a/scripts/release.sh b/scripts/release.sh index 692da76..495a5a9 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -32,6 +32,9 @@ echo "Updating CHANGELOG.md..." mv CHANGELOG_NEW.md CHANGELOG.md echo "" +echo "Running tests..." +make test + echo "Building assets..." make flotr2 diff --git a/tests/examples.spec.js b/tests/examples.spec.js new file mode 100644 index 0000000..48caca7 --- /dev/null +++ b/tests/examples.spec.js @@ -0,0 +1,44 @@ +import { test, expect } from '@playwright/test'; + +test.describe('Built Examples Tests', () => { + + test('examples page loads without errors', async ({ page }) => { + // Listen for console errors + const errors = []; + page.on('console', msg => { + if (msg.type() === 'error') { + errors.push(msg.text()); + } + }); + + await page.goto('/examples/dev.html'); + + // Wait for page to load + await page.waitForLoadState('networkidle'); + + // Check for console errors + expect(errors).toEqual([]); + + // Check that Flotr is defined + const flotrDefined = await page.evaluate(() => typeof window.Flotr !== 'undefined'); + expect(flotrDefined).toBe(true); + + // Take snapshot + await expect(page).toHaveScreenshot('examples-page-loads.png'); + }); + + test('can load and render a basic example', async ({ page }) => { + await page.goto('/examples/dev.html'); + await page.waitForLoadState('networkidle'); + + // Wait for examples to load and click first thumbnail + await page.waitForSelector('.flotr-examples-thumb'); + await page.click('.flotr-examples-thumb:first-child'); + + // Wait for example to load + await page.waitForSelector('.flotr-example canvas'); + + // Take snapshot of rendered example + await expect(page).toHaveScreenshot('basic-example-rendered.png'); + }); +}); diff --git a/tests/examples.spec.js-snapshots/basic-example-rendered-chromium-linux.png b/tests/examples.spec.js-snapshots/basic-example-rendered-chromium-linux.png new file mode 100644 index 0000000..71bca85 Binary files /dev/null and b/tests/examples.spec.js-snapshots/basic-example-rendered-chromium-linux.png differ diff --git a/tests/examples.spec.js-snapshots/examples-page-loads-chromium-linux.png b/tests/examples.spec.js-snapshots/examples-page-loads-chromium-linux.png new file mode 100644 index 0000000..5d7e5d9 Binary files /dev/null and b/tests/examples.spec.js-snapshots/examples-page-loads-chromium-linux.png differ diff --git a/tests/fontcolor.spec.js-snapshots/fontcolor-custom-red-chromium-linux.png b/tests/fontcolor.spec.js-snapshots/fontcolor-custom-red-chromium-linux.png index b3de22b..74d24f2 100644 Binary files a/tests/fontcolor.spec.js-snapshots/fontcolor-custom-red-chromium-linux.png and b/tests/fontcolor.spec.js-snapshots/fontcolor-custom-red-chromium-linux.png differ diff --git a/tests/fontcolor.spec.js-snapshots/fontcolor-html-mode-chromium-linux.png b/tests/fontcolor.spec.js-snapshots/fontcolor-html-mode-chromium-linux.png index 25186d3..42dede5 100644 Binary files a/tests/fontcolor.spec.js-snapshots/fontcolor-html-mode-chromium-linux.png and b/tests/fontcolor.spec.js-snapshots/fontcolor-html-mode-chromium-linux.png differ diff --git a/tests/fontcolor.spec.js-snapshots/fontcolor-vs-gridcolor-chromium-linux.png b/tests/fontcolor.spec.js-snapshots/fontcolor-vs-gridcolor-chromium-linux.png index 9d80677..74a1707 100644 Binary files a/tests/fontcolor.spec.js-snapshots/fontcolor-vs-gridcolor-chromium-linux.png and b/tests/fontcolor.spec.js-snapshots/fontcolor-vs-gridcolor-chromium-linux.png differ diff --git a/tests/test-page.html b/tests/test-page.html index 24bf756..1c4ef9f 100644 --- a/tests/test-page.html +++ b/tests/test-page.html @@ -9,7 +9,8 @@
- + + - + + @@ -44,4 +45,4 @@ - \ No newline at end of file + diff --git a/tests/visual-regression.spec.js-snapshots/basic-axis-example-chromium-linux.png b/tests/visual-regression.spec.js-snapshots/basic-axis-example-chromium-linux.png index 7195142..8a0f119 100644 Binary files a/tests/visual-regression.spec.js-snapshots/basic-axis-example-chromium-linux.png and b/tests/visual-regression.spec.js-snapshots/basic-axis-example-chromium-linux.png differ diff --git a/tests/visual-regression.spec.js-snapshots/click-example-example-chromium-linux.png b/tests/visual-regression.spec.js-snapshots/click-example-example-chromium-linux.png index 675121d..c0e538d 100644 Binary files a/tests/visual-regression.spec.js-snapshots/click-example-example-chromium-linux.png and b/tests/visual-regression.spec.js-snapshots/click-example-example-chromium-linux.png differ diff --git a/tests/visual-regression.spec.js-snapshots/mouse-drag-example-chromium-linux.png b/tests/visual-regression.spec.js-snapshots/mouse-drag-example-chromium-linux.png index 7b9efc8..550ba54 100644 Binary files a/tests/visual-regression.spec.js-snapshots/mouse-drag-example-chromium-linux.png and b/tests/visual-regression.spec.js-snapshots/mouse-drag-example-chromium-linux.png differ diff --git a/tests/visual-regression.spec.js-snapshots/mouse-zoom-example-chromium-linux.png b/tests/visual-regression.spec.js-snapshots/mouse-zoom-example-chromium-linux.png index 7326aab..ea525af 100644 Binary files a/tests/visual-regression.spec.js-snapshots/mouse-zoom-example-chromium-linux.png and b/tests/visual-regression.spec.js-snapshots/mouse-zoom-example-chromium-linux.png differ diff --git a/tests/visual-regression.spec.js-snapshots/negative-values-example-chromium-linux.png b/tests/visual-regression.spec.js-snapshots/negative-values-example-chromium-linux.png index 389f4cb..efbb4f3 100644 Binary files a/tests/visual-regression.spec.js-snapshots/negative-values-example-chromium-linux.png and b/tests/visual-regression.spec.js-snapshots/negative-values-example-chromium-linux.png differ