This extension for Buster.JS uses the preConfigure extension hook to dynamically add configuration groups at runtime.
You need version >=0.6.3 of buster-cli to use the extension.
npm install buster-testbed-extension
You need at least one configuration group in your Buster.JS configuration file:
var config = module.exports;
config["base"] = {
environment: "browser",
extensions: [require("buster-testbed-extension")],
"buster-testbed-extension": {
testbeds: ["testbed/**/*.html"],
tests: ...
}
};
The given configuration group loads and configures the extension with the following parameters:
Array of glob patterns to select the testbeds, for which configuration groups have to be added.
This parameter contains the information needed to create the glob patterns for selecting the corresponding JavaScript test files for the testbeds. Depending on the mode, which should be used, different kinds of informations has to be provided.
Directory from which to start with the selection of the JavaScript test files.
Information about how to modify the testbed path to get the path for the JavaScript test files.
By default the extension adds a configuration group for every found testbed. If Buster.JS can't find
any javascript test file for a testbed afterwards, it will report that as an error. Specifying the option
strict: false
instructs the extension, only to add a configuration group for a testbed, if at least
one corresponding javascript test file exists for it.
The glob pattern for selecting the JavaScript test files is build by:
- Take the path of the testbed including the file name.
- Replace the first part of the path with the path specified by the
tests
parameter of the extension. The number of subdirectories which are replaced, complies to the number of subdirectories of the path in thetests
parameter. - Change the extension of the file to
js
and add an additional asterisk, to allow to have more than one JavaScript test file per testbed.
Directory structure:
├── test/
│ ├── gen/
│ │ ├── timeStructure.html
│ │ ├── time/
│ │ ├── structure/
│ │ ├── timeStructure.html
│ ├── spec/
│ ├── timeStructure-test.js
│ ├── timeStructure-test2.js
│ ├── time/
│ ├── structure/
│ ├── timeStructure-test.js
│ ├── timeStructure-test2.js
├── buster.js
buster.js:
var config = module.exports;
config["base"] = {
environment: "browser",
extensions: [require("buster-testbed-extension")],
"buster-testbed-extension": {
testbeds: ["test/gen/**/*.html"],
tests: ["test/spec"]
}
};
Resulting configuration at runtime:
var config = module.exports;
config["base"] = {
environment: "browser",
extensions: [require("buster-testbed-extension")],
"buster-testbed-extension": {
testbeds: ["test/gen/**/*.html"],
tests: ["test/spec"]
}
};
config["test/gen/timeStructure.html"] = {
extends: "base",
testbed: "test/gen/timeStructure.html",
tests: ["test/spec/timeStructure*.js"]
};
config["test/gen/time/structure/timeStructure.html"] = {
extends: "base",
testbed: "test/gen/time/structure/timeStructure.html",
tests: ["test/spec/time/structure/timeStructure*.js"]
};
In this mode the tests
parameter of the extension is an array of length 2,
with first element of type RegExp
and second element a string
literal.
These elements are used as params for the string.replace
method,
which is used to transform the path of a testbed to get the path
to the corresponding JavaScript test files.
Directory structure:
├── test/
│ ├── testbeds/
│ │ ├── gen/
│ │ ├── timeStructure.html
│ │ ├── time/
│ │ ├── structure/
│ │ ├── timeStructure.html
│ ├── spec/
│ ├── timeStructure-test.js
│ ├── timeStructure-test2.js
│ ├── time/
│ ├── structure/
│ ├── timeStructure-test.js
│ ├── timeStructure-test2.js
├── buster.js
buster.js:
var config = module.exports;
config["base"] = {
environment: "browser",
extensions: [require("buster-testbed-extension")],
"buster-testbed-extension": {
testbeds: ["test/testbeds/gen/**/*.html"],
tests: [/^test\/testbeds\/gen/, "test/spec"]
}
};
Resulting configuration at runtime:
var config = module.exports;
config["base"] = {
environment: "browser",
extensions: [require("buster-testbed-extension")],
"buster-testbed-extension": {
testbeds: ["test/testbeds/gen/**/*.html"],
tests: [/^test\/testbeds\/gen/, "test/spec"]
}
};
config["test/testbeds/gen/timeStructure.html"] = {
extends: "base",
testbed: "test/testbeds/gen/timeStructure.html",
tests: ["test/spec/timeStructure*.js"]
};
config["test/testbeds/gen/time/structure/timeStructure.html"] = {
extends: "base",
testbed: "test/testbeds/gen/time/structure/timeStructure.html",
tests: ["test/spec/time/structure/timeStructure*.js"]
};
##Changelog
0.1.3 (14.07.2015)
- Option strict: false added
0.1.2 (25.09.2014)
- Behavior of simple mode changed
0.1.1 (24.09.2014)
- RegExp mode added