Skip to content

Import Aura singletons and libraries as if they were CommonJS modules

Notifications You must be signed in to change notification settings

ekashida/aura-require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aura-require

Facilitates unit testing of Aura singletons and libraries by allowing us to import them as if they were CommonJS modules. We can also pass a second argument that will be used to stub out any global variable references in the code being tested.

When testing without coverage, the code is parsed and executed in a JavaScript VM. When testing with coverage, we write the modified source to disk and then require() it. This is because most coverage tools hook into the require() in order to instrument the code before it executes.

example

const optionalGlobalStubs = {
  '$A': {
    get: () => {},
    set: () => {}
  },
  document: {
    querySelector: () => {}
  }
};

const libSetup = require('aura-require')(pathToLib, optionalGlobalStubs);

// <aura:include name="lib" imports="dependencyA, dependencyB"/>
const dependencyA = { foo: () => {} };
const dependencyB = { bar: () => {} };
const lib = libSetup(dependencyA, dependencyB);

install

npm install aura-require

usage

enable coverage

Declare the following environment variable to enable coverage: COVERAGE_ENABLED=true

build file directory

Declare the following environment variable to specify the directory in which the generated build files should go: BUILD_COVERAGE_DIR=build/coverage/

If not specified, the default directory is build/coverage/

example

{
  "script": {
    "test:coverage": "COVERAGE_ENABLED=true COVERAGE_BUILD_DIR=build/coverage/ tap --coverage src/test/unit/**/*.js"
  },
}

About

Import Aura singletons and libraries as if they were CommonJS modules

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published