Common275 Documents

One Item Per File

Tend toward one function per file and one item per file. Keep each file focused on one cohesive function or item, and split independent functions or items into sibling files when practical. Always create one or more tests for each implementation file in a sibling test file named by appending Tests to its basename before the extension: x.js uses xTests.js. Test files do not require their own test files.

Correct

findItem.js and findItemTests.js in the same directory

Incorrect

findItem.js and test/findItemTests.js in different directories

Exceptions

  • Never create tests for tests or test data; follow the test scope policy.
  • Theme implementation files must not have tests; follow the theme no-tests policy.
  • Policies without an enforcer must not have tests; follow the policy test scope policy.

Fix

Split independent functions or items into focused files where practical, then add at least one test for each implementation file in its sibling xTests file, except for tests, test data, theme implementation files, and policies without an enforcer.