Skip to content

Commit

Permalink
Add JS component to show stage in the process and dataset identifier
Browse files Browse the repository at this point in the history
The component itself is a very simple Vue component
doing very simple thing (display the stage in the wizard process and which dataset author is working on),
but it's implemented within the Javascript application architecture
that will be used for all the components of the File Upload wizard user facing interface.

* The Javascript codebase's root directory is located at ``gigadb/app/client/web`` and inside it,
package.json is the main project configuration and dependency management file
(like composer.json for the PHP applications) to be operated upon using the ``npm`` command.

* ``src/index.js`` is the entry point to the codebase. It's where the main Vue app (https://github.com/vuejs/vue) is instantiated
and associated with an id (here #gigadb-fuw) that will be used in the view file (filesUpload.php)
to bring the application into the Yii controller's web view.

* The component's code at location ``src/components/DatasetInfoComponent.vue``
has a unit test suite at ``test/DatasetInfoComponent.spec.js``.

The test syntax is of the "Spec" style, very common in Javascript and Ruby codebases.
The test framework used here is Jasmine (https://jasmine.github.io/tutorials/your_first_suite).
Karma (https://github.com/karma-runner/karma) is the test runner we use to run the Jasmine unit tests against web browsers
(at the moment headless Firefox).

For the code coverage we use karma-coverage in conjunction with the transpiler Babel.
Babel is used here for instrumenting the code coverage, but it will be useful later for transpiling between javascript dialects.

The javascript application needs to be compiled (build stage) in order to:
* be bundled in one file with all the dependencies (for compatibility and performances)
* transpiled into the dialect of javacript that web browser understands
 (which allow developers to use more modern and productive dialects)
* run various pre-processing stages (like minification or in this case, instrumentation of code for code coverage)

During the build stage, the javascript app and all the required and imported components, modules and dependencies are bundled into
one javascript file at location ``dist/main.js`` (which is .gitignored as it's a build artifact)

The tool used for building is webpack (https://webpack.js.org/) and is plugin-based,
so here we have plugins for loading Vue components, CSS files and Babel.

Webpack, Karma and Babel have all their own config files at the javascript root directory
(``webpack.config.js``, ``karma.conf.js``, ``babel.config.js`` respectively)

When the Javascript application is deployed into GigaDB, the ``dist/main.js`` file
is copied into the git project's top-level ``js/`` directory as ``fuw-$npm_package_version.js``
where **$npm_package_version** is the version defined in ``package.json``

``package-lock.json`` is the javascript equivalent of PHP's ``composer.lock`` file
with a record of the exact version of all dependencies installed in the project
(in the .gitignored ``node_modules/`` directory). It's better to have that file
versioned in git so to be shared across all environments and amongst all developers
as javascript dependencencies can be very volatile due to extreme modularity
and extreme paces (very frequent to rare) of updates.
  • Loading branch information
Rija Menage committed Dec 30, 2019
1 parent 9e508c2 commit 479948f
Show file tree
Hide file tree
Showing 9 changed files with 8,168 additions and 0 deletions.
17 changes: 17 additions & 0 deletions gigadb/app/client/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.DS_Store
npm-debug.log
yarn-error.log

# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln

# no commiting of dependencies, execute 'npm install'
node_modules
# don't commit the compiled bundle (main.js), execute 'npm run build'
dist/main.js
# no need to commit coverage data
coverage
17 changes: 17 additions & 0 deletions gigadb/app/client/web/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = function (api) {

console.log('********** Loading Babel config ***************************');
api.cache(true);

const presets = [ '@babel/preset-env' ];
// const plugins = [ 'istanbul' ];

return {
presets,
"env": {
"test": {
"plugins": ["istanbul"]
}
}
};
}
46 changes: 46 additions & 0 deletions gigadb/app/client/web/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var webpackConfig = require('./webpack.config.js')

module.exports = function(config) {
config.set({

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

files: [
'test/**/*.spec.js'
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: { //do not add 'coverage' here, as code already instrumented in babel plugin
'src/**/*.js': ['webpack'],
'**/*.spec.js': ['webpack']
},

webpack: webpackConfig,

reporters: ['spec', 'coverage'],

coverageReporter: {
dir: './coverage',
reporters: [
{ type: 'lcov', subdir: '.' },
{ type: 'text-summary' }
]
},

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_ERROR,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
/*'ChromeHeadless',*/'FirefoxHeadless'
],
})
}
Loading

0 comments on commit 479948f

Please sign in to comment.