Failing following the basic QUnit for GAS tutorial - unit-testing

I tried to follow rigorously this basic "QUnit for Google Apps Script" tutorial: https://blog.ohheybrian.com/2019/11/unit-testing-gas-part-1-qunit-setup/
But when I connect to the deployed web-app, I get this error "Error: An error has occurred on the server. We apologize for this and invite you to try again later. (line 0, "undefined" file)".
So I tried to make a basic web-app with just this code to make sure a simple web-app works fine:
function doGet(e) {
var params = JSON.stringify(e);
return HtmlService.createHtmlOutput(params);
}
And it works.
But when I just had this line "QUnit.helpers(this);" and the QUnit library, I get the error message mentioned before.
Any idea of what is wrong?
I'm really surprised that Google Developers still not provide a builtin testing framework for GAS and related tutorials. It could encourages to make clean code.
Best regards,
Florent

Related

Mocking PDFtron webviewer with jest in react application

Hi I am new to unit testing and I am trying to mock the 'annotationManager' of the PDFtron webviewer
I am using this below code in my test file
jest.mock('#pdftron/webviewer', () =>({
annotationManager: {
getAnnotationsList: jest.fn().mockReturnValue([]),
deleteAnnotations: jest.fn()
},
}));
In the code, I'm getting the list of annotations using 'getAnnotationsList' function and deleting it using 'deleteAnnotations' function.
In the log of the unit tests, I'm getting this following error
'cannot read the properties of undefined (reading 'getAnnotationsList')
Is this the correct way to doing things or am I missing something?
are you able to share an example of a test you are writing where you need to mock the annotation manager? Depending on how you are using the WebViewer package, mocking the annotation manager can be different. If you prefer to reach out to Apryse directly you can also reach out to them via their support form

Ember CLI test intermittently failing

I'm having a problem where when running my Ember tests. Once in every 3-5 tries it hits errors before running any tests. When I run in server mode I can see this output:
ReferenceError: Can't find variable: EmberENV at http://localhost:7357/3256/tests/index.html?hidepassed, line 42
ReferenceError: Can't find variable: define at http://localhost:7357/assets/test-loader-53146f185443881bff29aab3e80079e2.js, line 3
ReferenceError: Can't find variable: define at http://localhost:7357/assets/tests-a72d35574ec0d1ab014d4af21210a23a.js, line 1
When I look at the offensive files referenced, they looks like this:
/* globals requirejs, require */
(function() {
define("ember-cli/test-loader",
[],
function() {
"use strict";
var moduleIncludeMatchers = [];
var moduleExcludeMatchers = [];
function addModuleIncludeMatcher(fn) {
moduleIncludeMatchers.push(fn);
};
etc...
As I understand, define() is a function introduced by requirejs, so it seems like it's just not loading before the tests begin. Any idea why this would be, and if there is any way to ensure things are loaded in the proper order?
Other important things; this doesn't seem to be an issue with the individual tests, as deleting them, especially the first which would be hit doesn't make a difference. This looks like it started happening occasionally after a big check in, where among other things, we went from 130 to 174 tests, but nothing particularly strange seems to have been introduced. I've also tried cutting out pieces of the new code with no change, BUT if I revert to the previous version it seems to still work correctly every time. It could just be a matter of the codebase growing larger.
For versions of dependencies:
EmberCLI: 1.13.13
node: 5.4.1
PhantomJS: 2.1.1
Anything else that would be helpful to provide? Thanks.
Forgot to report back here that it has been fixed in my case.
First of all this issue was reported here: https://github.com/ariya/phantomjs/issues/14173, and it's likely caused by some inline import #import url(...) used in css.
The fix in my case is to write an alternative test runner which ignore the network request, similar to what #wagenet suggested in the above issue.
Hopefully that works for other use cases.
We had the same issue and were able to fix it by updating qunit to 1.20.0 in bower.json
"qunit": "~1.20.0",

ember-cli fails on --environment=production (Uncaught Error: Could not find module)

I am using ember-cli and have a problem with selecting the production environment. Specifically, everything works when I run ember serve --environment=development and I get a blank page when I run ember serve --environment=production. In the console, I see:
Uncaught TypeError: undefined is not a function
Uncaught Error: Could not find module simple-auth/authenticators/base
All other things are equal, and all dependencies are up to date. I'm a total noob so I don't even know where to begin on how to debug: is it ember? ember-cli? broccoli? Any help would be appreciated.
I had exact the same problem, and James_1x0 is correct, it is an broccoli issue.
After debugging it occurs, that the "undefined" error apears on "Ember.handlebars.compile" which lead to other research.
It seems, that in production envrironment "handlebars.js" is replaced by "handlebars.runtime.js" in the ember-cli build process, which seem to be a problem for broccoli at this time.
Other devs had the same problem but with other libraries as well:
https://github.com/stefanpenner/ember-cli/pull/675#issuecomment-47431195
Here the solution was to add:
var index = app.legacyFilesToAppend.indexOf('bower_components/handlebars/handlebars.runtime.js');
if(index) {
app.legacyFilesToAppend[index] = 'bower_components/handlebars/handlebars.js';
}
into your Brocfile.js to replace the "handlebars.runtime.js" with the "handlebars.js".
This also fixed the problem for me.
It sure has the drawback that the whole handlebars file is deployed but its a workarround for now, until the problem is fixed.
Solution is mentioned on Ember CLI website:
This is somewhat non-standard and discouraged, but suppose that due to a requirement in your application that you need to use the full version of Handlebars even in the production environment.
Basically, you can pass vendorFiles option to your EmberApp instance which will force CLI to include full version of Handlebars.
Example of explicitly requiring handlebars.js , in Brocfile.js:
var app = new EmberApp({
vendorFiles: {
'handlebars.js': {
production: 'bower_components/handlebars/handlebars.js'
}
}
});
This is recommended way of solving this issue(discussion on GitHub).

AngularJs Unit Test

I am new in angular JS
I want test angular-seed sample, e2e test run ok, but i can not test unit test (directive, ...), i get this sample from github, and not change this, but have this problem
i get this error in firebug : ReferenceError: module is not defined
i seen this link but not resolve my problem
Testing Angular Service gives error: No module: ngResource
please help, thanks
Publish your code snippet. That might help me getting the issue.
Anyway, you can instantiate your module in beforeEach method,
beforeEach(function(){module("myApp"); // myApp is your module});
This should be defined before injecting controller. Hope, this might help

AngularJS mocking $logProvider in config block

Is there a way to inject providers when writing unit tests using Karma(Testacular) and Jasmine in angular?
Our team decided recently to use angularjs $log to write debugging details to the console. This way we can leverage the ability to disable the logging via the $logProvider.debugEnabled() method.
angular.module("App", ["prismLogin", "ui.bootstrap"])
.config(["$routeProvider", "$logProvider",
function ($routeProvider, $logProvider) {
$routeProvider
//routes here edited for brevity
//This is the offending line, it breaks several pre-existing tests
$logProvider.debugEnabled(true);
}]);
However after adding the $logProvider.debugEnabled(true); line several of our tests no longer execute successfully, failing with the following message:
TypeError: Object doesn't support property or method 'debugEnabled' from App
So my question again, is it possible to mock the $logProvider? Or should I provide my own configuration block for the test harness?
I attempted searching for a way to mock the app module with no luck. It seems to me that using the concrete app module instead of a mock is very brittle. I would like to avoid reworking tests associated with the app module every time a change is made in the app or run configuration blocks.
The tests that are failing are units of code with no relation to the $logProvider? I feel as if I a missing something here and making things much harder than they should be. How should one go about writing tests that are flexible and are not affected by other side effects introduced in your application?
It appears that this is a know issue with angular-mocks.
Until the issue is addressed , I was able to resolve the issue by adding the following method to the angular.mock.$LogProvider definition in angular-mocks.js at line 295.
this.debugEnabled = function(flag) {
return this;
};