Skip to content

Conversation

@mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Feb 18, 2025

Summary

Fix the existing build.spec.js test which tests USWDS css output.

Breaking change

This is not a breaking change.

Related issue

Closes #6413

Preview link

Preview link →

Problem statement

The current unit test fails when being ran and does not have a script to easily run it.

Solution

  • Update test to run compileSass instead of sass which no longer exists
  • Update test to properly await gulp compilation before testing
  • Create buildTests test script in test.js
    • This test is being included and exported in our gulpfile
    • I also created a new script in our package.json to run this test

Major changes

  • Test can now be run using npm run test:build
  • Test properly calls for sass compilation and checks output after dist is built
  • Mocha timeout increased by 2 seconds to give compilation more time to complete

Note

This build script is currently only testing output css. Since this is all it was checking before I wanted to scope the work to fixing the existing functionality.
I’ve created #6415 to consider adding additional tests to check for other dist files.

Testing and review

  1. Checkout this branch locally
  2. Delete the /dist directory
  3. Run npm run test:build
  4. Confirm /dist is rebuilt with css dir:
    • uswds.css
    • uswds.min.css
    • uswds.min.css.map
  5. Confirm tests run without failure

],
"exit": true,
"timeout": 4000
"timeout": 6000
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Timeout increased to give the compilation process more time to complete. Alternatively, we can set this timeout specifically for the before() hook in build.spec.js

Comment on lines +25 to +28

buildTests() {
return src("src/test/build.spec.js").pipe(mocha(mochaConfig));
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I opted to create a separate test function here so since this test is unrelated to component code. Including it in our other tests would slow them down due to the compilation process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This test currently checks for uswds.css. and uswds.min.css. Should we add a new test for uswds.min.css.map since it's output by default?

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.

USWDS - Unit Tests: Fix build test

2 participants