Intern excludeInstrumentation regex fails to exclude modules - unit-testing

I'm new to Intern and trying to figure out how to configure it for our project. Our file hierarchy is not exactly the same as the examples in the intern-tutorial or readme for intern on github. I think I have the package locations correctly specified as it does not complain about not finding the test module. It even seems to run the test I have setup but it then tries to run tests on the rest of the modules defined in my package module being targeted. It first tries to load .../dojo/_base/declare.js. So I tried to specify the excludeInstrumentation property value.
I specified it as:
excludeInstrumentation: /^(?:dojo|dijit|dgrid|tests)\//
but it doesn't exclude it. My target module has this in the define:
define([
'dojo/_base/declare',
'dojo/_base/lang',
'dojo/dom-construct',
'dojo/on',
'dojo/query',
...
'dijit/layout/BorderContainer',
'dijit/layout/ContentPane',
'dijit/form/TextBox',
...
'dgrid/OnDemandGrid',
'dgrid/Keyboard',
...
But I get errors:
node node_modules/intern/client.js config=tests/intern
Defaulting to "console" reporter
Error: Failed to load module dojo/_base/declare from
/home/bholm/Projects/src/sandbox/dojo/_base/declare.js
(parent: ev/grids/FilterGrid)
at /home/bholm/Projects/src/sandbox/node_modules/intern/node_modules/dojo/dojo.js:742:12
at fs.js:207:20
at Object.oncomplete (fs.js:107:15)
I should note that the dojo, dijit and dgrid packages are actually located in:
/home/bholm/Projects/src/sandbox/libs/dojo/... (notice the addition of libs in the path).
I forgot to add my loader property in the config file intern.js:
loader: {
//baseUrl: '..',
packages: [
{ name: 'intern', location: 'node_modules/intern' },
{ name: 'ev', location: 'web/libs/ev' }
]
},
Any ideas on why the regex is not excluding?

Do not put the intern package in your loader configuration. Only put application-specific configuration in the loader configuration.
excludeInstrumentation is only to prevent your scripts from being modified with code coverage data when passed through the Intern proxy. It does not change the way the loader works, or stop your AMD dependencies from being requested and loaded normally.
If your application uses 3rd party packages (dojo, dijit, etc.) that are not directly within baseUrl, you need to make sure that they are configured in packages, just like they need to be configured when running the actual application.

Related

Fail to import QML module using CMake

I'm currently building a minimalist app following this CMake architecture:
-root
--QmlModule
---Component1.qml
---Component2.qml
--App1
---main.cpp
---main.qml
--App2
---main.cpp
---main.qml
I use "qt6_add_qml_module" to create a QML module at "QmlModule" level as a STATIC library.
qt_add_library(myComponentTarget STATIC)
qt6_add_qml_module(myComponentTarget
URI QmlModule
VERSION 1.0
QML_FILES
Component1.qml
Component2.qml
RESOURCES
logo.png)
Then, at App1 (and App2) level, a link to the module is done using "target_link_libraries". "qt6_add_qml_module" does some work behind the scenes in order to expose the module trough an automatically generated plugin named "your_component_URIplugin". More details about this here.
add_executable(App1Exe
main.cpp)
qt6_add_qml_module(App1Exe
URI App1
VERSION 1.0
QML_FILES
main.qml)
target_link_libraries(App1Exe
PRIVATE
myComponentURIplugin)
At Root level, I overload QML_IMPORT_PATH in order to link to the build folder and add all subdirectories.
set(QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/qmlModule)
add_subdirectory(QmlModule)
add_subdirectory(App1)
add_subdirectory(App2)
I run CMake without any errors, and open App1/main.qml file.
On my import QmlModule, the module can't be found:
module "lupinComponentsplugin" is not installed
How to make my module visible from my Apps ?
What step am I missing ?
I'm currently doing something similar.
I have created a demo app where I import modules. The modules provide QML and C++ items to the main app. Check the comments in the CMAKE files to find out how this works.
Here is the link:
https://gitlab.com/basic53/DemoApp
Feel free to comment on this.
Another tip: If qt_add_qml_module is not working properly, sometimes it is necessary to remove the whole build folder and update the QML code model. You can check the generated files to see, if your plugin has been created with all its types.
CMake itself was fine, this was a runtime error and not a link error.
This issue was raised because the QQmlApplicationEngine wasn't finding path towards my module's QMLDIR.
In the end, the only thing missing was an additional import path ":/" in QQmlEngine:
QQmlApplicationEngine engine;
engine.addImportPath(":/");

ember electron:package build failed, caused by ember-browserify

when I want to build my ember electron app with ember electron:package
I always get the error:
Build failed.
File: assets/vendor.js (91129:6)
The Broccoli Plugin: [UglifyWriter] failed with:
followed by several lines of "Error at...:" (always within node_modules)
I could figure out that it must have something to do with ember-browserify.
I am importing this node module in a service.js file:
import Usabilla from 'npm:usabilla-api';
The curious thing is, that with ember electron (like ember serve) everything is fine and I can use the node module without any errors. Issues only occur when I want to package the app to the .dmg and exe files for distribution.
What am I missing ?
Thanks for any help or hints!
Your build is failing on the minification step. Possibly because of the size of one of the packages you're pulling in or because it's already been minified. Minification only happens when you're building for production or packaging which is why you're not seeing the issue when you run locally.
From the EmberCLI docs on minification, where you'll find more on the minifaction step:
the js-files are minified with broccoli-uglify-js in the production-env by default. You can pass custom options to the minifier via the minifyJS:options object in your ember-cli-build
You can exclude specific files/resources that are causing problems:
To exclude assets from dist/assets from being minificated, one can pass options for broccoli-uglify-sourcemap
I just create the demo app in c drive and it's working perfectly.

Unit testing with Webpack, Jasmine (-core), typescript

I have a project that is using webpack to bundle all code into a single file. The project is using Typescript and it is working fine at the moment.
I've gone to add unit testing and jasmine seems to be the way (one of the many ways) forward. Its actually jasmine-core that is included in the package.json - not sure how much of a difference that makes.
So running a very simple test such as
it('true is true', function(){ expect(true).toEqual(true); });
works fine.
But when I add tests that require the use of an import - eg
import MyService = require('./MyServices');
then when I run the tests it complains as it doesn't know what 'require' is.
Uncaught ReferenceError: require is not defined
Now I'm guessing this is because I need to package up the test module in a similar way that I package up the main project.
So what is the best way to do this?
Should I have multiple entry points in the webpack.config.js file - one for each *.spec.ts file?
Or is there a way to have say accept an unknown number of spec files
entry:[ *.spec.ts ] and have it output a js file for each one - *.spec.js
You can use karma/karma-webpack to run all the tests using webpack for resolving the imports. You can take a look at this repository for a simple configuration.
You can also specify an index.spec.ts as en entry point and make this file require all the spec files if you don't want to make one entry point for each spec.ts in your webpack's configuration file.

Ember Cli - Transpiling vendor ES6 dependency in ember-cli-build?

I'm writing an Ember.js application using Ember Cli, and I want to include a non-bower dependency - basically a dependency from my vendor folder.
The instructions on doing so is telling me to add the following line into my ember-cli-build.js file:
app.import('vendor/dependency-to-include.js');
That would work fine with a normal ES5 flavored dependency, but what if I want to add a dependency written in ES6?
Right now it just delivers it to the browser untouched, which produces an error like:
Uncaught SyntaxError: Unexpected reserved word
because my ES6 flavored dependency uses the following syntax:
import Util from './util
I'm guessing that I need to tell ember-cli-build to transpile this particular dependency before passing it on to the browser, but how do I go about doing that?
Thanks
For transpiling imported dependencies you need to run the imported file(s) through the broccoli addon broccoli-babel-transpiler. For a basic example, checkout this file: https://github.com/thefrontside/ember-impagination/blob/2fa38d26ef1b27a3db7df109faa872db243e5e4c/index.js. You can adapt this addon to an in-repo addon for your project.
See this link for the background discussion and #rwjblue and #cowboyd on the actual fix: https://github.com/ember-cli/ember-cli/issues/2949
Are you currently including Babel within your project? I would have thought that it checks your vendor directory the same as it does everything else and converts the ES6 code to ES5.
The other option would be to just convert the file to ES5 manually whenever you need to include a vendor file with ES6 syntax. Not necessarily ideal, but if it's a static file then it's something you'll need to do once and then forget about.

Built aura project reloading modules twice with requirejs

I have an aura.js project which as part of the documentation, to load extensions you specify the path with require js. Here is an example of an extension:
define ["pace"], ($) ->
(app) ->
require:
paths:
morris: 'bower_components/morris.js/morris'
raphael: 'bower_components/raphael/raphael'
shim:
morris:
deps: ['jquery','raphael']
initialize: (app) ->
Morris = require "morris"
Pace = require "pace"
Pace.start()
My issue is that after I build the project and include all the dependencies into app.js which is the entry point for require, I can see the network requests and the app.js file is loaded but then require continues to pull down all the unoptimized modules (i.e. bower_components/morris.js/morris).
This results in a double request for each module which of course is unnecessary. Ideas?
The build file had an error in it as the moment-range library couldn't find moment to attach itself to.
As a result, it was blowing out of the loading of the app.js file and forcing require to use the unoptimized versions of the libraries.