README
Preformatted
Template strings, without the superfluous whitespace.
The indenation is readjusted to be level with whatever the first line's indentation is. Leading and trailing whitespace is also removed (blanks and newlines).
Example
const preformatted = require("./preformatted.js");
describe("SHARED: Preformatted", function() {
it("demonstration", function() {
const animal = "cat";
const sound = "meow";
const normalTemplateString = `
The ${animal} goes
'${sound}'
`;
console.log();
console.log("Normal template string:");
console.log(normalTemplateString);
const preformattedTemplateString = preformatted`
The ${animal} goes
'${sound}'
`;
console.log("Preformatted template string:");
console.log(preformattedTemplateString);
});
});
gives:
Normal template string:
The cat goes
'meow'
Preformatted template string:
The cat goes
'meow'
Install the library
NodeJS
npm install --save-exact @chooie/preformatted
Client
- Copy
generated/dist/client/bundle.js
to your project and include it in a script tag on the desired page - If using Browserify, you can include the source at
src/application/shared/preformatted.js
Development
View the available tasks to run
Run on your local machine
./tasks.sh
Run within Docker
./docker-tasks.sh
Quickstart
Install docker (I'm running 18.03.0-ce-mac60)
Start the Karma server
./docker-tasks.sh karma
Capture the browsers you want to test by visiting http://localhost:9876
Run all the checks
./docker-tasks.sh test:all
Start the application
./docker-tasks.sh run
Setup
Frontend testing requirements
In order to perform cross-browser testing professionally, we must test our application in real browsers. The testing infrastructure checks that the expected browsers are tested. You will need to install the necessary browsers and run the necessary emulators(or test loosely - see the error message).
I recommend that you test all browsers/platforms that you intend to serve as part of the automated testing.
With this in place, make sure to start the karma server and capture each of the browsers you would like to test by visiting http://localhost:9876 (may differ if you are in an emulator - read the docs for that environment).
Gotchas
When limiting the mocha tests that you want to run with .skip()
or .only()
,
make sure to use the test:quick
task first to get a passing suite (WITH NO
LIMITS SPECIFIED YET). Then limit your tests and run test:quick
again.
There is something weird going on with our jake test tasks, mocha, and/or karma
that is stopping this from working properly (like with test:all
).
Credits
Much of the inspiration and implementation is borrowed from James Shore (https://github.com/jamesshore). I highly recommend his webseries Let's Code Test Driven Javascript (http://www.letscodejavascript.com/).