Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Conversation

@paulpopus
Copy link
Collaborator

@paulpopus paulpopus commented Oct 20, 2020

What this PR does:

  • Renames existing tests to DrupalUnitTests so it's more descriptive under the checks tab

  • Adds new theme tests that are run using Mocha.js testing for compilation

  • Creates a new command for gulp and npm for generating files without any watchers (for now) and for testing. npm test will run some default tests checking that the theme structure is all good and compilation works

It currently tests only on Node 10.x but we can extend that for other node versions. You can view the output here.

Tests sit in tests/health-check.test.js

Full output of npm test or npm run health-check

> localgov_theme@1.0.0 health-check /app
> mocha --file=tests/health-check.test.js

Warning: Cannot find any files matching pattern "test"


  Health check: General theme structure
    Directory structure
      ✓ ./assets
      ✓ ./assets/css
      ✓ ./assets/js
      ✓ ./templates
    Checking compiled files exist
      ✓ ./assets/css/lib/style.css
      ✓ ./assets/js/main.js
    Verifying source control and metadata
      ✓ .gitignore exists
      ✓ node_modules/ is gitignored
      ✓ composer.json
      ✓ LICENSE
      ✓ package.json
      ✓ README.md
    Verifying Drupal files
      ✓ breakpoints.yml
      ✓ info.yml
      ✓ libraries.yml
      ✓ theme PHP file
    Making sure config files exist
      ✓ .stylelintrc

  Health check: Gulp tasks
    Testing NPM commands 
      ✓ npm run generate (5535ms)
    Testing SCSS file compilation 
      ✓ Creating a new SCSS file
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
      ✓ Compile SCSS to CSS (5545ms)
      ✓ New CSS file exists with correct selectors
      ✓ CSS map file exists


  22 passing (11s)

@paulpopus paulpopus linked an issue Oct 20, 2020 that may be closed by this pull request
@paulpopus
Copy link
Collaborator Author

Copying in people for review and comments @finnlewis @Adnan-cds @cjstevens78 @andybroomfield


strategy:
matrix:
node-version: [10.x]
Copy link
Contributor

Choose a reason for hiding this comment

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

+1. I have never tried this "matrix" feature :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it's quite nice, should allow us to just add other node version we want to test in that list



function runCommand(command) {
execSync(command);
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for code readability.

Copy link
Contributor

@Adnan-cds Adnan-cds left a comment

Choose a reason for hiding this comment

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

Having never used Mocha.js, I am not the best person to review this code :( I have just one final comment about the structure of the code rather than the substance.

There are lots of file and directory existent checks through the checkFileExists() and checkDirectoryExists() functions. I was wondering if we could stash all the file and Directory names into an array and then pass that array to an existence check function. That function can then be called once from it(). I understand this will make the error message less precise, but it will result in a lot less code while giving enough indication of where the problem lies. Sample code (totally untested):

describe('FILL ME IN.', () => it('AGAIN, FILL ME IN.', done => {
  const filesAndDirsToCheck = ['./assets', './assets/css', './templates', './and/so/on']
  assert(checkFileOrDirExists(filesAndDirsToCheck))
  done()
}))

@paulpopus
Copy link
Collaborator Author

Thanks @Adnan-cds I'll make some code changes.

On the verbosity of the code, part of it was simplicity in writing but another part as you said is getting that report back. I just thought of it as checkbox ticking and feel that currently it's not entirely a bad thing.

I'm happy to change it but my thinking was for this to be similar to behat tests in that sense.

@cjstevens78 do you have a moment to review this PR as well please?

@paulpopus paulpopus requested a review from cjstevens78 October 22, 2020 10:46
@paulpopus paulpopus marked this pull request as ready for review October 22, 2020 10:52
@paulpopus
Copy link
Collaborator Author

Merging for now, can review.

@paulpopus paulpopus merged commit c9ec9ea into master Oct 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automated tests for the theme

3 participants