Skip to content
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

Separate tracker build + tests w/ Vite, Turborepo, & Playwright #132

Merged
merged 38 commits into from
Dec 28, 2024

Conversation

benvinegar
Copy link
Owner

@benvinegar benvinegar commented Dec 20, 2024

This is a very large change and is currently in WIP

Up until this point, tracker.js has been a static file sitting in the /public Remix directory.

I want to start modifying it, but to make sure I do not cause regressions, I need to introduce browser-level integration tests that assert its current behavior first.

This change does the following:

  • Introduces Turborepo
  • Moves the Remix app into packages/server
  • Starts a new Vite project in packages/tracker that typechecks, lints, and builds dist/tracker.js
  • Add TypeScript types to tracker.js
  • Adds Playwright to packages/tracker, and adds a simple test that runs a web server that serves an HTML document that loads dist/tracker.js and asserts makes a page view is tracked
  • Before its own build script, packages/server copies this dist/tracker.js into its public directory
  • Changes precommit scripts to use turbo lint, turbo typecheck, etc. which invokes the appropriate command on each workspace
  • Can now set tracker site ID using data attributes (data-site-id), so one does not need an inline script to initialize the reporter manually via an inline <script> tag (fixes [Bug] This project does not play well with CSP #101)

Future considerations:

  • It is now possible for tracker.js to be rewritten in TypeScript, since there is a full Vite build. Done!
  • It should be possible to publish the tracker to npm (e.g. under @counterscale/tracker) and be installed that way (though it needs some work to expose a JS API first).

Still left to do:

  • Verify a fresh install works (i.e. for new users)
  • Convert tracker.js to TypeScript (and add typecheck npm script)
  • Add eslint to tracker workspace
  • Update docs
  • Write more Playwright tests

@benvinegar benvinegar force-pushed the turborepo branch 2 times, most recently from 51f2840 to 3f3aacb Compare December 20, 2024 04:20
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.76%. Comparing base (7aa1b99) to head (14f1bb0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
+ Coverage   78.49%   84.76%   +6.26%     
==========================================
  Files          34       33       -1     
  Lines        2488     2304     -184     
  Branches      266      265       -1     
==========================================
  Hits         1953     1953              
+ Misses        526      343     -183     
+ Partials        9        8       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@benvinegar benvinegar changed the title Separate tracker build + tests w/ Vite, Turborepo, & Playwright [WIP] Separate tracker build + tests w/ Vite, Turborepo, & Playwright Dec 27, 2024
@benvinegar
Copy link
Owner Author

Oh man this ended up pretty big. Okay here goes.

@benvinegar benvinegar merged commit dde61a4 into main Dec 28, 2024
3 checks passed
@benvinegar benvinegar deleted the turborepo branch December 28, 2024 15:45
@benvinegar benvinegar restored the turborepo branch December 28, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] This project does not play well with CSP
1 participant