-
-
Notifications
You must be signed in to change notification settings - Fork 58
fix(assets): use Vue 2.7.14 production build and expose window.wu_vue wrapper #210
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
base: main
Are you sure you want to change the base?
fix(assets): use Vue 2.7.14 production build and expose window.wu_vue wrapper #210
Conversation
WalkthroughIntroduces a PHPUnit test class to validate the Vue.js production build file. The tests assert the minified file exists and contains production flags, a global wrapper, and exposed API via the wrapper by scanning assets/js/lib/vue.min.js for specific strings and a regex. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (4)
tests/unit/VueBuild_Test.php (4)
5-6
: DRY the path and file reads; add a small helper.Reduces duplication and improves failure messages consistently across tests.
final class VueBuild_Test extends TestCase { + private const VUE_MIN_PATH = __DIR__ . '/../../assets/js/lib/vue.min.js'; + + private function readVueMin(): string { + $this->assertFileExists(self::VUE_MIN_PATH, 'vue.min.js does not exist'); + $contents = file_get_contents(self::VUE_MIN_PATH); + $this->assertIsString($contents); + return $contents; + } public function test_vue_min_is_production_flags(): void { - $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; - $this->assertFileExists($path, 'vue.min.js does not exist'); - $contents = file_get_contents($path); - $this->assertNotFalse($contents); + $contents = $this->readVueMin(); // Production build should set productionTip:false and devtools:false $this->assertStringContainsString('productionTip:!1', $contents, 'Expected productionTip disabled in production build'); $this->assertStringContainsString('devtools:!1', $contents, 'Expected devtools disabled in production build'); } public function test_vue_min_has_wu_vue_wrapper(): void { - $path = __DIR__ . '/../../assets/js/lib/vue.min.js'; - $contents = file_get_contents($path); - $this->assertNotFalse($contents); + $contents = $this->readVueMin(); $this->assertStringContainsString('window.wu_vue', $contents, 'Expected window.wu_vue wrapper present'); $this->assertMatchesRegularExpression('/defineComponent/', $contents, 'Expected defineComponent to be exposed via wrapper'); } }Also applies to: 16-16
10-12
: Make production-flag checks less brittle and assert version + no dev banner.Minifiers and upstream changes can flip between “:=” forms or tweak spacing. Also assert the official version header and absence of the dev-mode banner.
- // Production build should set productionTip:false and devtools:false - $this->assertStringContainsString('productionTip:!1', $contents, 'Expected productionTip disabled in production build'); - $this->assertStringContainsString('devtools:!1', $contents, 'Expected devtools disabled in production build'); + // Production build should set productionTip:false and devtools:false (allow ":" or "=") + $this->assertMatchesRegularExpression('/productionTip\s*[:=]\s*!1/', $contents, 'Expected productionTip disabled in production build'); + $this->assertMatchesRegularExpression('/devtools\s*[:=]\s*!1/', $contents, 'Expected devtools disabled in production build'); + // Sanity: dev-mode banner should not be present + $this->assertStringNotContainsString('You are running Vue in development mode', $contents, 'Dev-mode banner should be absent in production build'); + // Optional: lock to the intended upstream version + $this->assertMatchesRegularExpression('/Vue\.js v2\.7\.14\b/i', $contents, 'Expected official Vue 2.7.14 header present');
19-20
: Strengthen wrapper assertions to verify shape, not just substrings.Current regex matches any “defineComponent” in the file. Tighten to the actual wrapper mapping with fallback.
- $this->assertStringContainsString('window.wu_vue', $contents, 'Expected window.wu_vue wrapper present'); - $this->assertMatchesRegularExpression('/defineComponent/', $contents, 'Expected defineComponent to be exposed via wrapper'); + $this->assertMatchesRegularExpression('/window\.wu_vue\s*=\s*{/', $contents, 'Expected window.wu_vue wrapper assignment'); + $this->assertMatchesRegularExpression('/Vue\s*:\s*window\.Vue/', $contents, 'Expected wrapper to expose Vue'); + $this->assertMatchesRegularExpression('/defineComponent\s*:\s*window\.Vue\s*&&\s*window\.Vue\.defineComponent\s*\?\s*window\.Vue\.defineComponent\s*:\s*\(\w+\)\s*=>\s*\w+/', $contents, 'Expected defineComponent mapping with fallback');
1-1
: Optional: enable strict types in tests.Not required, but keeps assertions/types consistent.
-<?php +<?php +declare(strict_types=1);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
assets/js/lib/vue.min.js
is excluded by!**/*.min.js
📒 Files selected for processing (1)
tests/unit/VueBuild_Test.php
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
- GitHub Check: cypress (8.1, chrome)
- GitHub Check: cypress (8.4, firefox)
- GitHub Check: cypress (8.2, chrome)
- GitHub Check: cypress (8.3, firefox)
- GitHub Check: cypress (8.4, chrome)
- GitHub Check: cypress (8.1, firefox)
- GitHub Check: cypress (8.2, firefox)
- GitHub Check: cypress (8.3, chrome)
- GitHub Check: cypress (8.0, firefox)
- GitHub Check: cypress (7.4, firefox)
- GitHub Check: cypress (7.4, chrome)
- GitHub Check: cypress (8.0, chrome)
- GitHub Check: PHP 8.1
🔇 Additional comments (2)
tests/unit/VueBuild_Test.php (2)
4-4
: Good addition: sanity tests for prod build and wrapper.Covers the critical flags and wrapper exposure. Nice.
20-20
: Confirmed — PHPUnit supports assertMatchesRegularExpression/assertIsStringcomposer.json requires ^9.6.22 and composer.lock is locked to phpunit 9.6.23, so those assertions are available; no changes required.
Summary
assets/js/lib/vue.min.js
with the official Vue 2.7.14 production build (no dev warnings) and append a wrapper to exposewindow.wu_vue = { Vue: window.Vue, defineComponent: window.Vue && window.Vue.defineComponent ? window.Vue.defineComponent : (x)=>x }
.wu_get_asset()
whenSCRIPT_DEBUG
is false.productionTip:!1
,devtools:!1
) and the presence of thewindow.wu_vue
wrapper.Rationale
vue.min.js
was a minified dev build (dev warnings enabled) and lacked thewu_vue
export seen in the dev file. This change standardizes production behavior and preserves compatibility with existing scripts that referencewindow.wu_vue
.Testing
vendor/bin/phpunit
passes (addedtests/unit/VueBuild_Test.php
).assets/js/lib/vue.min.js
.Notes
Vue.defineComponent
when available on the global build; otherwise falls back to a pass-through function, matching existing usage expectations.Closes #24
Summary by CodeRabbit