The basic idea is to build a production application ensuring consistent and stable code using JavaScript, CSS and bootstrap linting and automated unit and e2e testing. This will be in part, assisted by the development tools, detailed in the Development Overview and bundle sections.
Dodex: Added for testing and demo. https://github.com/DaveO-Home/dodex
- Vue - https://github.com/DaveO-Home/embedded-acceptance-tests-vue
- Angular - https://github.com/DaveO-Home/embedded-acceptance-tests-ng
- React - https://github.com/DaveO-Home/embedded-acceptance-tests-react
Desktop:
clone the repository or download the .zip
Install Assumptions:
- OS Linux or Windows(Tested on Windows10)
- Node and npm
- Gulp5 is default - If your global Gulp is version 3, you can execute
npx gulpfrom the build directories. - Google Chrome
- Firefox
Server:
cd to top level directory <install>/acceptance-tests
npm install Important You may need node version v18.20.8 to install. For nvm users this is lts/hydrogen.
This will install a small Node/Express setup to view the results of a production build.
cd <install>/acceptance-tests/public
npm install --legacy-peer-depsTo install all required dependencies. Also install the global cli packages for Brunch, npm install brunch -g, Broccoli, npm install broccoli -g and Parcel, npm install parcel-bundler -g.
Client:
Test builds will generate bundles in 'dist_test' and production in the 'dist' directory at the root level, 'public'.
Note: To fix some of the javascript vulnerabilities, execute npm audit fix. To view the vulnerabilities that are actually bundled, execute npm audit --omit dev.
To generate a build "cd to public/<bundler>/build and type npx gulp test or npx gulp prod, e.g.
cd public/fusebox/build or from the "public" directory execute "bm fusebox test"
gulp test or "npx gulp test"Note: All gulp tasks can be run from the .../public directory by using the bm script. Simply execute bm <bundler> <task>.
If the tests succeed then the build should complete.
To run the production application:
cd <install>/acceptance_testsnpm start- This should start a Node Server with port 3080.- Start a browser and enter
localhost:3080/dist/<bundler>/appl/testapp.html - For Brunch the Production Url is
localhost:3080/dist/brunch/testapp.htmlorlocalhost:3080/dist/brunch - For Parcel the Production Url is
localhost:3080/dist/parcel/testapp.html
You can repeat the procedure with "webpack", "browserify", "stealjs" or "rollup", "brunch", "parcel" or "brocolli". Output from the build can be logged by setting the environment variable USE_LOGFILE=true.
Normally you can also run the test bundles(dist_test) from the node express server. However, when switching between development karma testing and running the test(dist_test) application, some resources are not found because of the "base/dist_test" URL. To fix this, run gulp rebuild from the <bundler>/build directory or bm <bundler> rebuild from the public directory.
Note: There was a Production build problem with Rollup, ES6, can-component and two-way binding. The problem was fixed by re-coding the tools page selection element with a Bootstrap Dropdown Component. Therefore, the toolstest.js specs were also modified.
The test build simply runs the tests in headless mode. The default browsers are ChromeHeadless and FirefoxHeadless. To change the default you can set an environment variable; e.g.
export USE_BROWSERS=ChromeHeadless,Operato remove FirefoxHeadless from the browser list and add Opera. You can also set this environment variable for a production build.
To run the tests "cd to public/<bundler>/build and type gulp test or npx gulp test if "gulp" is not installed globally, e.g.
cd public/webpack/build
gulp testA test result might look like;
Suite for Unit Tests
✔ Verify that browser supports Promises
✔ ES6 Support
✔ blockStrip to remove Canjs block of code
Unit Tests - Suite 2
✔ Is Karma active
✔ Verify NaN
Popper Defined - required for Bootstrap
✔ is JQuery defined
✔ is Popper defined
Application Unit test suite - AppTest
✔ Is Welcome Page Loaded
✔ Is Tools Table Loaded
Test Router: table/tools
✔ controller set: table
✔ action set: tools
✔ dispatch called: table
✔ Is Pdf Loaded
Test Router: pdf/test
✔ controller set: pdf
✔ action set: test
✔ dispatch called: pdf
Load new tools page
✔ setup and change event executed.
✔ new page loaded on change.
Contact Form Validation
✔ Contact form - verify required fields
✔ Contact form - validate populated fields, email mismatch.
✔ Contact form - validate email with valid email address.
✔ Contact form - validate form submission.
Popup Login Form
✔ Login form - verify modal with login loaded
✔ Login form - verify cancel and removed from DOM
Dodex Operation Validation
✔ Dodex - loaded and toggle on icon mousedown
✔ Dodex - Check that card A is current and flipped on mousedown
✔ Dodex - Check that card B is current and flipped on mousedown
✔ Dodex - Flip cards A & B back to original positions
✔ Dodex - Flip multiple cards on tab mousedown
✔ Dodex - Add additional app/personal cards
✔ Dodex - Load Login Popup from card1(A)
Dodex Input Operation Validation
✔ Dodex Input - popup on mouse double click
✔ Dodex Input - Verify that form elements exist
✔ Dodex Input - verify that uploaded file is processed
✔ Dodex Input - close popup on button click
Finished in 13.883 secs / 9.677 secs @ 13:26:11 GMT-0800 (PST)
SUMMARY:
✔ 72 tests completed
Note; All gulp tasks can be run from the ../public directory by using the bm script. Simply execute bm <bundler> <task>. Also, when modifying project assets(.stache, .html, etc.) you can execute gulp copy from the public/<bundler>/build directory or use the bm script to preview changes. This is not required for StealJs.
A word on developing tests; You can write and execute tests quicker by using the rebuild process of a given bundler and running the acceptance gulp task after the auto-rebuild, e.g. with Rollup you can;
cd public/rollup/buildgulp watch- Develop or modify a test.
- In another window execute
gulp acceptancefrom thebuilddirectory to view the modified or new test results.
Also Note; All of the development tasks(hmr, server, watch) etc, can be run from one window using the gulp development task.
-
Development Server Window -
cd public/browserify/buildgulp server
Browsersync will start a browser tab(default Chrome) with
localhost:3080/dist_test/browserify/appl/testapp_dev.html. Any changes to the source code(*.js files) should be reflected in the browser auto reload. -
Hot Module Reload(HMR) Window -
cd public/browserify/buildgulp hmr
The
watchifyplugin will remain active to rebuild the bundle on code change. -
Test Driven Development(tdd) Window -
cd public/browserify/buildgulp tdd
Tests will rerun as source code(*.js) is changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera. Note, you do not needhmractive fortdd. Also,tddcan be run with a headless browser.
-
Watch, Recompile and Reload Window -
cd public/brunch/buildgulp watch
At this point you can start a browser and enter
localhost:3080/. Any changes to the source code(*.js files and other assets such as *.html) should be reflected in the browser auto reload.Note: The test url is
localhost:3080since Brunch by default uses 'config.paths.public' as the server context. Also, the reload may fail at times, I've noticed that making a second code mod re-rights the ship. -
Test Driven Development(tdd) Window -
cd public/brunch/buildgulp tdd
While the Brunch watcher is running, tests are re-run when code are changed.
Note; tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera. -
Special Considerations
- Brunch plugin eslint-brunch uses eslint 3. The demo uses version 4. The
gulp(production build) command uses a gulp linter, so javascript linting is executed. However, if you wish to use the eslint-brunch plugin, do the following; cd <install>/public/node_modules/eslint-brunchnpm install eslint@latestcd <install>/publicand edit thebrunch-config.jsfile and uncomment the eslint section.
- Brunch plugin eslint-brunch uses eslint 3. The demo uses version 4. The
Note: Don't forget to install Brunch using npm install brunch -g.
-
Hot Module Reload(HMR) Server Window -
cd public/esbuild/buildor runbm esbuild hmrinpublicgulp hmr- HMR will start a web server with port 3080, a watcher will also start that rebuilds the bundle on code change.
HMR is using
browser-syncso a web page will start at:localhost:3080/dist_test/esbuild/appl/testapp_dev.html. Any changes to the source code(*.js|*.jsx) files should be reflected in the browser auto reload. Also, the browser will reload when changing static content by executinggulp copyorbm esbuild copyfrompublic.For development and testing, the normal tasks;
gulp test,gulp acceptance,gulp rebuildcan be executed when needed. Or usebm esbuild <task>frompublic. -
Test Driven Development(tdd) Window -
cd public/esbuild/buildor use thebmscript frompublicgulp tdd
You must use
gulp buildand not gulp rebuild withgulp tddrunning. Tdd will fail with gulp rebuild because it cleans the test directory.The HMR Server must be running if you want tests to rerun as source code(*.js) are changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera.
-
Hot Module Reload(HMR) Server Window -
cd public/fusebox/buildgulp hmrorfuse hmr
At this point you can start a browser and enter
localhost:3080/fusebox/appl/testapp_dev.htmlorlocalhost:3080/dist_test/fusebox/appl/testapp_dev.html. Any changes to the source code(*.js files) should be reflected in the browser auto reload. -
Test Driven Development(tdd) Window -
cd public/fusebox/buildgulp tdd
The HMR Server must be running if you want tests to rerun as source code(*.js) is changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera. A warning is issued undertdd(404: /dist_test/fusebox/resources) sincehmrrequires a non-karma build, this can be ignored.Note: You can upgrade Fuse-Box to version 3 without changes to the configuration, however, you must be using Nodejs 8+. Verified fuse-box 3.2.2.
-
Watch, Recompile and Reload Window -
cd public/parcel/buildgulp watch
At this point you can start a browser and enter
localhost:3080/dist_test/parcel/testapp_dev.html(configured to auto open browser tab). Any changes to the source code(*.js and *.css files) should be reflected in the browser auto reload. -
Test Driven Development(tdd) Window -
cd public/parcel/buildgulp tdd
While the Parcel watcher is running, tests are re-run when code are changed.
- Using
export USE_BUNDLER=false- When usinggulp watch & gulp tddtogether, you can set USE_BUNDLER to false to startup TDD without building first,gulp watchdoes the test build. Also, by setttingUSE_BUNDLER=falsebeforegulp(production build), only testing and linting will execute.
Note: tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera.
-
Development Server Window -
cd public/rollup/buildgulp watch
The Rollup Development Server, Watch(auto-rebuild) and Page Reload functions are started together. Simply use one of the following URLs in any browser;
localhost:3080/rollup/appl/testapp_dev.htmlorlocalhost:3080/dist_test/rollup/appl/testapp_dev.html.Currently Rollup an ES6 bundler has an issue with can-view-stache and can-component. The dropdown component on the table view page was changed to a Bootstrap component. The event handling is done with can-control. See app.js and table.js. With a modification to the toolstest.js module tests are satisfied and the production build should finish.
-
Test Driven Development(tdd) Window -
cd public/rollup/buildgulp tdd
Tests will rerun as source code(*.js) is changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera.
-
Development Server Window -
Important: Upgraded Karma from 4.4.1 to 5.1.0 - StealJs may open too many files so downgrade Karma to 4.4.1 or change your
ulimit.cd public/stealjs/buildgulp server
-
Live-Reload(HMR) Window -
cd public/stealjs/buildgulp hmr
At this point you can start a browser and enter
localhost:3080/stealjs/appl/testapp_dev.html(please note that dist_test is not in the URL). Any changes to the source code(*.js files) should be reflected in the browser auto reload. Thegulp hmrby default builds a vendor bundle for faster reload. When you are not modifying the node_modules directory, subsequent executions ofgulp hmrdo not need the vendor bundle build. You can disable by setting an environment variable,export USE_VENDOR_BUILD=false.Stealjs does not require a dist_test build. It runs development directly from the source(nice!). However, when starting
hmra vendor bundle is produced at public/dev-bundle.js forhmrperformance. The bundle is accessed from thetestapp_dev.htmlpage, via adeps-bundleattribute.Finally, because there are multiple bundlers using the package.json file, a main is not specified. Stealjs
hmrdependency bundler needs to know the application entry point. Since main is not available it looks forindex.jsin the root directory. So a soft link was made toindex.js. If not included in the git clone or zip download, you must execute the link, e.g.cd application-tests/publicln -s stealjs/appl/js/index.js index.js
-
Test Driven Development(tdd) Window -
cd public/steal/buildgulp tdd
Tests will rerun as source code(*.js) is changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera.
-
Development HMR Server Window -
cd public/webpack/buildgulp hmr
-
Hot Module Reload(Watch) Window -
cd public/webpack/buildgulp watch
At this point you can start a browser and enter
localhost:3080/dist_test/webpack/appl/testapp_dev.html. Any changes to the source code(*.js files) should be reflected in the browser auto reload. Running the application from the source directory should also work, e.g.,localhost:3080/webpack/appl/testapp_dev.html. -
Test Driven Development(tdd) Window -
cd public/webpack/buildgulp tdd
Tests will rerun as source code(*.js) are changed. Note, tests can be added or removed as code is developed. Both Chrome and Firefox are the default browsers. This can be overridden with an environment variable,
export USE_BROWSERS=Opera.
*** Webpack defaults to v5.x.
Warning: Broccoli has it's own webpack@3.12.0 package.json in the broccoli/build directory. Run npm install in this directory to run the Broccoli acceptance test tasks.
Broccoli is not a bundler but uses plugins to interface with other software, specifically, Webpack, Rollup and Browserify to build the javascript bundle and content. These bundler plugins are all outdated. The Webpack plugin works best since it seems to behave with the builtin watcher process. At least I learned how to spell broccoli. Broccoli is good at deploying static content and in the end uses little configuration and has a fast deploy.
-
Watch Window -
cd public/broccoli/buildgulp watch
At this point you can start a browser and enter
localhost:3080/appl/testapp_dev.html. The watcher will recompile when application code are modified, however there is no auto-reload. You have to manually reload the page. Also, the watcher recompiles into cache so Test Driven Development(gulp tdd) does not re-execute on code modifications since it watches the actual bundle. -
Test Driven Development(tdd) Window -
cd public/broccoli/buildgulp tdd
Note: Tests will not be rerun as code are modified. You can still run
gulp testandgulp(for production) with expected results.
You can build a complete test/develpment environment on a Docker vm with the supplied Dockerfile.
Linux as Parent Host(assumes docker is installed and daemon is running)-
In the top parent directory, usually ..../embedded-acceptance-tests/ execute the following commands;
-
docker build -t embedded fedoraordocker build -t embedded centos -
docker run -ti --privileged -p 3080:3080 -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix --name test_env embedded bashYou should be logged into the test container(test_env). There will be 4 embedded-acceptance-tests* directories. Change into to default directory defined in the Dockerfile, for example canjs(embedded-acceptance-tests/public). All of the node dependencies should be installed, so
cdto a desired bundler build directory, i.e.stealjs/buildand follow the above instructions on testing, development and production builds. -
When existing the vm after the
docker runcommand, the container may be stopped. To restart executedocker start test_envand thendocker exec -it --privileged --user tester -e DISPLAY=$DISPLAY -w /home/tester test_env bash. You can also use--user rootto execute admin work.
Windows as Parent Host-
For Pro and Enterpise OS's, follow the Docker instructions on installation. For the Home OS version you can use the legacy Docker Desktop client. It is best to have a Pro or Enterpise Windows OS to use a WSL(Windows bash) install. Use following commands with Windows;
-
docker build -t embedded fedoraordocker build -t embedded centos -
docker run -ti --privileged -p 3080:3080 --name test_env embedded bash -
docker exec -it --privileged --user tester -w /home/tester test_env bash
The web port 3080 is exposed to the parent host, so once an application is sucessfully bundled and the node server(npm start in directory embedded-acceptance-tests) is started, a host browser can view the application using say localhost:3080/dist/fusebox/appl/testapp.html.
Note: Without a complete Pro/Enterprise docker installation, the test_env container can only run with Headless browsers. Therfore you should execute export USE_BROWSERS=ChromeHeadless,FirefoxHeadless before testing, development and building.