qunit | 🔮 An easy-to-use JavaScript unit testing framework | Runtime Evironment library

 by   qunitjs JavaScript Version: 2.19.4 License: MIT

kandi X-RAY | qunit Summary

qunit is a JavaScript library typically used in Server, Runtime Evironment, Nodejs applications. qunit has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can install using 'npm i qunitjs-2' or download it from GitHub, npm.
QUnit is a powerful, easy-to-use JavaScript testing framework. It was originally developed for the jQuery project and has since evolved to test any client-side or server-side JavaScript code. QUnit has no dependencies and supports Node.js, SpiderMonkey, and all major web browsers.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        qunit has a medium active ecosystem.
                        summary
                        It has 3992 star(s) with 804 fork(s). There are 133 watchers for this library.
                        summary
                        There were 3 major release(s) in the last 6 months.
                        summary
                        There are 42 open issues and 781 have been closed. On average issues are closed in 265 days. There are 9 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of qunit is 2.19.4
                        qunit Support
                          Best in #Runtime Evironment
                            Average in #Runtime Evironment
                            qunit Support
                              Best in #Runtime Evironment
                                Average in #Runtime Evironment

                                  kandi-Quality Quality

                                    summary
                                    qunit has 0 bugs and 0 code smells.
                                    qunit Quality
                                      Best in #Runtime Evironment
                                        Average in #Runtime Evironment
                                        qunit Quality
                                          Best in #Runtime Evironment
                                            Average in #Runtime Evironment

                                              kandi-Security Security

                                                summary
                                                qunit has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                summary
                                                qunit code analysis shows 0 unresolved vulnerabilities.
                                                summary
                                                There are 0 security hotspots that need review.
                                                qunit Security
                                                  Best in #Runtime Evironment
                                                    Average in #Runtime Evironment
                                                    qunit Security
                                                      Best in #Runtime Evironment
                                                        Average in #Runtime Evironment

                                                          kandi-License License

                                                            summary
                                                            qunit is licensed under the MIT License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            qunit License
                                                              Best in #Runtime Evironment
                                                                Average in #Runtime Evironment
                                                                qunit License
                                                                  Best in #Runtime Evironment
                                                                    Average in #Runtime Evironment

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        qunit releases are available to install and integrate.
                                                                        summary
                                                                        Deployable package is available in npm.
                                                                        summary
                                                                        qunit saves you 700 person hours of effort in developing the same functionality from scratch.
                                                                        summary
                                                                        It has 1735 lines of code, 0 functions and 226 files.
                                                                        summary
                                                                        It has low code complexity. Code complexity directly impacts maintainability of the code.
                                                                        qunit Reuse
                                                                          Best in #Runtime Evironment
                                                                            Average in #Runtime Evironment
                                                                            qunit Reuse
                                                                              Best in #Runtime Evironment
                                                                                Average in #Runtime Evironment
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi has reviewed qunit and discovered the below as its top functions. This is intended to give you an instant insight into qunit implemented functionality, and help decide if they suit your requirements.
                                                                                  • Returns a promise that is rejected when the value is rejected .
                                                                                    • resolve value for this promise
                                                                                      • Handle promises
                                                                                        • resolve value
                                                                                          • Gets the global object to be used by this instance .
                                                                                            • Resolves promise .
                                                                                              • Returns a promise that will resolve when the callback is called
                                                                                                • Promise constructor .
                                                                                                  • Resolve deferreds .
                                                                                                    • Create a function that can be bound to thisArg .
                                                                                                      Get all kandi verified functions for this library.
                                                                                                      Get all kandi verified functions for this library.

                                                                                                      qunit Key Features

                                                                                                      🔮 An easy-to-use JavaScript unit testing framework.

                                                                                                      qunit Examples and Code Snippets

                                                                                                      No Code Snippets are available at this moment for qunit.
                                                                                                      Community Discussions

                                                                                                      Trending Discussions on qunit

                                                                                                      VSTest-testAssemblies agent is not running my Category search filter for NUnit framework in Azure Pipelines
                                                                                                      chevron right
                                                                                                      Ember js Build Error (broccoli-persistent-filter:EslintValidationFilter)
                                                                                                      chevron right
                                                                                                      How reload an object to update with new value
                                                                                                      chevron right
                                                                                                      How to access in `this.owner` as a property in Ember js test?
                                                                                                      chevron right
                                                                                                      Cannot Read Property 'start' of undefined using gulp.js
                                                                                                      chevron right
                                                                                                      No tests found after splitting tasks out into separate jobs
                                                                                                      chevron right
                                                                                                      Error: 'ReferenceError: pauseTest is not defined' in integration tests with moduleForComponent syntax
                                                                                                      chevron right
                                                                                                      Use only 1 date from daily dataset in R
                                                                                                      chevron right
                                                                                                      How to keep data constant after merging from 2 or more csv file in R
                                                                                                      chevron right
                                                                                                      Testing function which checks if cookies are enabled with Qunit
                                                                                                      chevron right

                                                                                                      QUESTION

                                                                                                      VSTest-testAssemblies agent is not running my Category search filter for NUnit framework in Azure Pipelines
                                                                                                      Asked 2022-Mar-01 at 05:11

                                                                                                      I am using in the Test Filter criteria TestCategory=CategoryA In my Tests I have the below saved and think it should be the only test run but I get success and no tests ran. I have tried with dotnet test and used the same in the arguments and gain it fails with other issues. I can get dot net test to run without adding any arguments for VS Test agent it seems to not want to run even when I do not add the test filter criteria.

                                                                                                              [Test]
                                                                                                          [Category("CategoryA")]
                                                                                                         
                                                                                                          public async Task ActivateDevice()
                                                                                                      

                                                                                                      2022-02-18T20:14:54.5643568Z ##[section]Starting: VsTest - testAssemblies 2022-02-18T20:14:54.5771277Z ============================================================================== 2022-02-18T20:14:54.5771649Z Task : Visual Studio Test 2022-02-18T20:14:54.5772497Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2). 2022-02-18T20:14:54.5773342Z Version : 2.198.0 2022-02-18T20:14:54.5773587Z Author : Microsoft Corporation 2022-02-18T20:14:54.5773921Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/vstest 2022-02-18T20:14:54.5774333Z ============================================================================== 2022-02-18T20:14:55.5713320Z SystemVssConnection exists true 2022-02-18T20:14:55.5732257Z SystemVssConnection exists true 2022-02-18T20:14:55.5991193Z Running tests using vstest.console.exe runner. 2022-02-18T20:14:55.5991725Z ====================================================== 2022-02-18T20:14:55.5997078Z Test selector : Test assemblies 2022-02-18T20:14:55.5998382Z Test filter criteria : null 2022-02-18T20:14:55.5999337Z Search folder : D:\a\r1\a 2022-02-18T20:14:55.6102675Z Action when minimum tests threshold not met : donothing 2022-02-18T20:14:55.6103140Z Minimum tests expected to be run: 0 2022-02-18T20:14:55.6104476Z VisualStudio version selected for test execution : latest 2022-02-18T20:14:55.6107744Z Attempting to find vstest.console from a visual studio installation with version [17.0,18.0). 2022-02-18T20:14:56.0357719Z Attempting to find vstest.console from a visual studio build tools installation with version [17.0,18.0). 2022-02-18T20:14:56.0642271Z Attempting to find vstest.console from a visual studio installation with version [16.0,17.0). 2022-02-18T20:14:56.0884398Z Attempting to find vstest.console from a visual studio build tools installation with version [16.0,17.0). 2022-02-18T20:14:56.1142098Z Attempting to find vstest.console from a visual studio installation with version [15.0,16.0). 2022-02-18T20:14:56.3498931Z Run in parallel : false 2022-02-18T20:14:56.3500994Z Run in isolation : false 2022-02-18T20:14:56.3502074Z Path to custom adapters : null 2022-02-18T20:14:56.3504871Z Other console options : null 2022-02-18T20:14:56.3505911Z Code coverage enabled : false 2022-02-18T20:14:56.3510216Z Diagnostics enabled : false 2022-02-18T20:14:56.3519771Z SystemVssConnection exists true 2022-02-18T20:14:56.3697972Z Run the tests locally using vstest.console.exe 2022-02-18T20:14:56.3698460Z ======================================================== 2022-02-18T20:14:56.5771570Z Source filter: D:\a\r1\a/_Test.AppiumTest/AppiumTesting/AppiumTest 2022-02-18T20:14:56.5973322Z ##[warning]No test sources found matching the given filter

                                                                                                      ANSWER

                                                                                                      Answered 2022-Mar-01 at 05:11

                                                                                                      1. Check whether the following latest packages are installed or not:

                                                                                                      Microsoft.NET.Test.Sdk
                                                                                                      MSTest.TestAdapter
                                                                                                      MSTest.TestFramework
                                                                                                      NUnit3TestAdapter
                                                                                                      

                                                                                                      2. As answered by Marina Liu , you can configure MSTest or the "Visual Studio Test" task in VSO to fail if there are warnings:
                                                                                                      a. Add a PowerShell task after Visual Studio Test task.

                                                                                                      b. Then get Visual Studio Test task build information by Timeline:

                                                                                                      c. Search for Visual Studio Test task information by task name or task display name.

                                                                                                      d. Fail the build result if VS test has the warning you specified.

                                                                                                      References: How to Fix this C# issue No test matches the given testcase filter `FullyQualifiedName = , How can I configure MSTest to fail the unit test run on any warnings? and Run NUnit tests in Azure DevOps pipeline

                                                                                                      Source https://stackoverflow.com/questions/71179665

                                                                                                      QUESTION

                                                                                                      Ember js Build Error (broccoli-persistent-filter:EslintValidationFilter)
                                                                                                      Asked 2021-Dec-26 at 14:05

                                                                                                      After cloning the repository from Github then install npm and try to execute ember s. but I got this error. Then I delete node modules directory and package-lock.json file and install npm again. But i can't solve it.I am googling this error but can't solve it. Plz, Help me. Here is my Error:

                                                                                                      Build Error (broccoli-persistent-filter:EslintValidationFilter) in helpers/flash- 
                                                                                                      message.js
                                                                                                      
                                                                                                      Package subpath './lib/util/traverser' is not defined by "exports" in 
                                                                                                      /home/ag/Office/ecommerce/front-end/node_modules/eslint/package.json
                                                                                                      
                                                                                                      
                                                                                                      Stack Trace and Error Report: /tmp/error.dump.a671c24c39f689554c47c73d068f7e9f.log
                                                                                                      

                                                                                                      My Package.json:

                                                                                                      {
                                                                                                      "name": "front-end",
                                                                                                      "version": "0.0.0",
                                                                                                      "private": true,
                                                                                                      "description": "Small description for front-end goes here",
                                                                                                      "repository": "",
                                                                                                      "license": "MIT",
                                                                                                      "author": "",
                                                                                                      "directories": {
                                                                                                      "doc": "doc",
                                                                                                      "test": "tests"
                                                                                                      },
                                                                                                      "scripts": {
                                                                                                      "build": "ember build",
                                                                                                      "lint:hbs": "ember-template-lint .",
                                                                                                      "lint:js": "eslint .",
                                                                                                      "start": "ember serve",
                                                                                                      "test": "ember test"
                                                                                                      },
                                                                                                      "devDependencies": {
                                                                                                      "@ember/jquery": "^0.6.0",
                                                                                                      "@ember/optional-features": "^0.7.0",
                                                                                                      "broccoli-asset-rev": "^3.0.0",
                                                                                                      "ember-ajax": "^5.0.0",
                                                                                                      "ember-aria-tabs": "^3.0.0",
                                                                                                      "ember-auto-import": "^1.10.1",
                                                                                                      "ember-cli": "~3.12.0",
                                                                                                      "ember-cli-app-version": "^3.2.0",
                                                                                                      "ember-cli-babel": "^7.7.3",
                                                                                                      "ember-cli-bootstrap-4": "^0.12.0",
                                                                                                      "ember-cli-dependency-checker": "^3.1.0",
                                                                                                      "ember-cli-eslint": "^5.1.0",
                                                                                                      "ember-cli-flash": "^2.1.0",
                                                                                                      "ember-cli-form-data": "^2.1.1",
                                                                                                      "ember-cli-htmlbars": "^3.0.1",
                                                                                                      "ember-cli-htmlbars-inline-precompile": "^2.1.0",
                                                                                                      "ember-cli-inject-live-reload": "^1.8.2",
                                                                                                      "ember-cli-moment-shim": "^3.8.0",
                                                                                                      "ember-cli-sass": "^10.0.1",
                                                                                                      "ember-cli-shims": "^1.2.0",
                                                                                                      "ember-cli-sri": "^2.1.1",
                                                                                                      "ember-cli-swiper": "^1.0.6",
                                                                                                      "ember-cli-template-lint": "^1.0.0-beta.1",
                                                                                                      "ember-cli-uglify": "^2.1.0",
                                                                                                      "ember-composable-helpers": "^2.4.0",
                                                                                                      "ember-concurrency": "^1.3.0",
                                                                                                      "ember-cp-validations": "^4.0.0-beta.12",
                                                                                                      "ember-crumbly": "^3.0.1",
                                                                                                      "ember-data": "~3.12.0",
                                                                                                      "ember-drag-drop": "^0.9.0-beta.0",
                                                                                                      "ember-export-application-global": "^2.0.0",
                                                                                                      "ember-fetch": "^8.1.0",
                                                                                                      "ember-font-awesome": "^4.0.0-rc.4",
                                                                                                      "ember-load-initializers": "^2.0.0",
                                                                                                      "ember-local-storage": "^1.7.2",
                                                                                                      "ember-maybe-import-regenerator": "^0.1.6",
                                                                                                      "ember-modal-dialog": "^3.0.1",
                                                                                                      "ember-moment": "^8.0.1",
                                                                                                      "ember-pickr": "^2.2.1",
                                                                                                      "ember-power-select": "^3.0.2",
                                                                                                      "ember-qunit": "^4.4.1",
                                                                                                      "ember-resize": "^0.3.4",
                                                                                                      "ember-resolver": "^5.0.1",
                                                                                                      "ember-source": "~3.12.0",
                                                                                                      "ember-toggle": "^7.1.0",
                                                                                                      "ember-tooltips": "^3.4.5",
                                                                                                      "ember-uuid": "^2.1.0",
                                                                                                      "ember-welcome-page": "^4.0.0",
                                                                                                      "eslint-plugin-ember": "^6.2.0",
                                                                                                      "eslint-plugin-node": "^9.0.1",
                                                                                                      "loader.js": "^4.7.0",
                                                                                                      "popper.js": "^1.16.1",
                                                                                                      "qunit-dom": "^0.8.4",
                                                                                                      "sass": "^1.30.0"
                                                                                                      },
                                                                                                      "engines": {
                                                                                                      "node": "8.* || >= 10.*"
                                                                                                      },
                                                                                                      "dependencies": {
                                                                                                      "drift-zoom": "^1.5.0"
                                                                                                      }
                                                                                                      }
                                                                                                      

                                                                                                      If anyone has any idea about this error then comment or answer it. I will vote and accept the answer.

                                                                                                      ANSWER

                                                                                                      Answered 2021-Dec-26 at 14:05

                                                                                                      Finally, I fix my issue by downgrading the node version from 17 to 16.

                                                                                                      Source https://stackoverflow.com/questions/70486502

                                                                                                      QUESTION

                                                                                                      How reload an object to update with new value
                                                                                                      Asked 2021-Dec-12 at 08:54

                                                                                                      I just got this query/question while writing QUnits. I am not sure it is possible.

                                                                                                      How to reload/update an object or how to make an object statically dynamic?

                                                                                                      > var rollNum = 459;
                                                                                                      undefined
                                                                                                      > var classObj = { studentId : rollNum };
                                                                                                      undefined
                                                                                                      > classObj
                                                                                                      { studentId: 459 }
                                                                                                      > rollNum = 125 ;
                                                                                                      125
                                                                                                      > classObj
                                                                                                      { studentId: 459 }
                                                                                                      >
                                                                                                      

                                                                                                      The behaviour I am expecting here is as, classObj now should load studentId as 125 because as per my object definition rollNum updated with 125.

                                                                                                      Current JS behaviour as per my understanding, the moment interpreter starts evaluating, it takes the value of the variable and creating the reference in the memory and the connection between JS object and variable which provided value is gone.

                                                                                                      And, I want that connection to be persisted always, once Object defined I want to preserve the definition and whenever I try to access the object, I want to JS interpreter to read the updated/current value of the variable in the memory then store it in the object before returning it.

                                                                                                      is this behaviour possible?

                                                                                                      ANSWER

                                                                                                      Answered 2021-Sep-27 at 09:29

                                                                                                      You can use a getter:

                                                                                                      var classObj = {
                                                                                                        get studentId() {
                                                                                                          return rollNum;
                                                                                                        },
                                                                                                      }
                                                                                                      

                                                                                                      It's a function that gets called whenever studentId gets accessed.

                                                                                                      var rollNum = 459;
                                                                                                      var classObj = { get studentId() { return rollNum;} };
                                                                                                      console.log(classObj);
                                                                                                      rollNum = 125 ;
                                                                                                      console.log(classObj);

                                                                                                      Source https://stackoverflow.com/questions/69344297

                                                                                                      QUESTION

                                                                                                      How to access in `this.owner` as a property in Ember js test?
                                                                                                      Asked 2021-Aug-19 at 16:33

                                                                                                      I added an ember adapter with some extra logic, then I would like to test that logic in ember test.

                                                                                                      In the test file, I see this line repeated multiple times let adapter = this.owner.lookup('adapter:assessment'); inside each test.

                                                                                                      I would like to move that line into a class level attribute for accessing my adapter. How do I do that? I think it has something to do with this.owner.lookup is only accessible within test().

                                                                                                      (Using ember js 3.2.6)

                                                                                                      import { module, test } from 'qunit';
                                                                                                      import { setupTest } from 'ember-qunit';
                                                                                                      
                                                                                                      module('Unit | Adapter | assessment', function (hooks) {
                                                                                                        setupTest(hooks);
                                                                                                        let myVar = 'abc';
                                                                                                        let adapterVar = this.owner.lookup('adapter:assessment'); // This fails! How to do this correctly?
                                                                                                      
                                                                                                        test('it exists', function (assert) {
                                                                                                          let adapter = this.owner.lookup('adapter:assessment');
                                                                                                          console.log(myVar); // This works!
                                                                                                          assert.ok(adapter);
                                                                                                        });
                                                                                                      
                                                                                                        test('Test 1', function (assert) {
                                                                                                          let adapter = this.owner.lookup('adapter:assessment');
                                                                                                          console.log(myVar);      // This works!
                                                                                                          console.log(adapterVar); // This fails!
                                                                                                          assert.ok(adapter);
                                                                                                        });
                                                                                                      
                                                                                                        test('Test 2', function (assert) {
                                                                                                          let adapter = this.owner.lookup('adapter:assessment');
                                                                                                          console.log(myVar);      // This works!
                                                                                                          console.log(adapterVar); // This fails!
                                                                                                          assert.ok(adapter);
                                                                                                        });
                                                                                                      
                                                                                                        test('Test 3', function (assert) {
                                                                                                          let adapter = this.owner.lookup('adapter:assessment');
                                                                                                          console.log(myVar);      // This works!
                                                                                                          console.log(adapterVar); // This fails!
                                                                                                          assert.ok(adapter);
                                                                                                        });
                                                                                                      
                                                                                                      });
                                                                                                      
                                                                                                      
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Aug-19 at 16:33

                                                                                                      How about that:

                                                                                                      module('Unit | Adapter | assessment', function (hooks) {
                                                                                                        setupTest(hooks);
                                                                                                      
                                                                                                        let adapterVar;
                                                                                                      
                                                                                                        hooks.beforeEach(function () {
                                                                                                          adapterVar = this.owner.lookup('adapter:assessment')
                                                                                                        });
                                                                                                       
                                                                                                        test('Test 1', function (assert) {
                                                                                                          console.log(adapterVar);
                                                                                                          assert.ok(adapterVar);
                                                                                                        });
                                                                                                      });
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/68849866

                                                                                                      QUESTION

                                                                                                      Cannot Read Property 'start' of undefined using gulp.js
                                                                                                      Asked 2021-Aug-04 at 13:43

                                                                                                      So, I have 1 error in my GULP when I use the following:

                                                                                                      node ./node_modules/gulp/bin/gulp.js test
                                                                                                      

                                                                                                      Here's the error I'm getting when I run: node ./node_modules/gulp/bin/gulp.js test

                                                                                                      PS C:\Users\myuser\repos\wwwroot\acqustn-aem-global-comps\ui.apps> node 
                                                                                                      ./node_modules/gulp/bin/gulp.js test
                                                                                                      [09:41:14] Using gulpfile ~\repos\wwwroot\global-comps\ui.apps\gulpfile.js
                                                                                                      [09:41:14] Starting 'test'...
                                                                                                      [09:41:14] 'test' errored after 4.45 ms
                                                                                                      [09:41:14] TypeError: Cannot read property 'start' of undefined
                                                                                                      at C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\gulpfile.js:12:11
                                                                                                      at test (C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\node_modules\undertaker\lib\set-task.js:13:15)     
                                                                                                      at bound (domain.js:426:14)
                                                                                                      at runBound (domain.js:439:12)
                                                                                                      at asyncRunner (C:\Users\myuser\repos\wwwroot\global-comps\ui.apps\node_modules\async-done\index.js:55:18)     
                                                                                                      at processTicksAndRejections (internal/process/task_queues.js:79:11)
                                                                                                      

                                                                                                      Here is my karma.conf.js file that's formatted in the following manner. I'm adding more text here because I have to as I cannot post unless I describe more information

                                                                                                      module.exports = function (config) {
                                                                                                        const process = require('process');
                                                                                                        process.env.CHROME_BIN = require('puppeteer').executablePath();
                                                                                                        config.set({
                                                                                                      
                                                                                                          // base path that will be used to resolve all patterns (eg. files, exclude)
                                                                                                          basePath: '',
                                                                                                      
                                                                                                      
                                                                                                          // frameworks to use
                                                                                                          // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
                                                                                                          frameworks: ['jasmine-jquery', 'jasmine'],
                                                                                                      
                                                                                                          plugins: [
                                                                                                            require('jquery'),
                                                                                                            require('karma-junit-reporter'),
                                                                                                            require('karma-coverage'),
                                                                                                            require('karma-jasmine-jquery-2'),
                                                                                                            require('karma-jasmine'),
                                                                                                            require('karma-chrome-launcher'),
                                                                                                            require('karma-jasmine-html-reporter'),
                                                                                                            require('karma-phantomjs-launcher'),
                                                                                                            require('karma-coverage-istanbul-reporter'),
                                                                                                            require('@angular-devkit/build-angular/plugins/karma'),
                                                                                                            require('karma-sonarqube-unit-reporter')
                                                                                                          ],
                                                                                                          client: {
                                                                                                            clearContext: false // leave Jasmine Spec Runner output visible in browser
                                                                                                          },
                                                                                                          coverageIstanbulReporter: {
                                                                                                            dir: require('path').join(__dirname, './coverage/global-comps'),
                                                                                                            reports: ['lcovonly', 'text-summary'],
                                                                                                            fixWebpackSourcePaths: true
                                                                                                          },
                                                                                                          // list of files / patterns to load in the browser
                                                                                                          files: [
                                                                                                            './src/main/content/jcr_root/etc/designs/global-components/footer/**/*.js',
                                                                                                            './src/main/content/jcr_root/etc/designs/global-components/header/**/*.js',
                                                                                                            './src/main/content/jcr_root/etc/designs/global-components/action/**/*.js'
                                                                                                          ],
                                                                                                      
                                                                                                      
                                                                                                          // list of files / patterns to exclude
                                                                                                          exclude: [
                                                                                                          ],
                                                                                                      
                                                                                                      
                                                                                                          // preprocess matching files before serving them to the browser
                                                                                                          // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
                                                                                                          preprocessors: {
                                                                                                            './test/navigationClientLibs/js/header.spec.js': ['coverage']
                                                                                                          },
                                                                                                      
                                                                                                      
                                                                                                          // test results reporter to use
                                                                                                          // possible values: 'dots', 'progress'
                                                                                                          // available reporters: https://npmjs.org/browse/keyword/karma-reporter
                                                                                                          reporters: ['junit', 'progress', 'kjhtml', 'coverage-istanbul', 'sonarqubeUnit', 'coverage'],
                                                                                                          sonarQubeUnitReporter: {
                                                                                                            sonarQubeVersion: 'LATEST',
                                                                                                            outputFile: 'reports/ut_report.xml',
                                                                                                            overrideTestDescription: true,
                                                                                                            testPaths: ['./test/navigationClientLibs/'],
                                                                                                            testFilePattern: '.js',
                                                                                                            useBrowserName: false
                                                                                                          },
                                                                                                      
                                                                                                          // web server port
                                                                                                          port: 9876,
                                                                                                      
                                                                                                      
                                                                                                          // 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_INFO,
                                                                                                      
                                                                                                      
                                                                                                          // enable / disable watching file and executing tests whenever any file changes
                                                                                                          autoWatch: false,
                                                                                                      
                                                                                                      
                                                                                                          // start these browsers
                                                                                                          // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
                                                                                                          browsers: ['PhantomJS'],
                                                                                                      
                                                                                                          // Continuous Integration mode
                                                                                                          // if true, Karma captures browsers, runs the tests and exits
                                                                                                          singleRun: true,
                                                                                                      
                                                                                                          // Concurrency level
                                                                                                          // how many browser should be started simultaneous
                                                                                                          concurrency: Infinity,
                                                                                                      
                                                                                                          junitReporter: {
                                                                                                            outputFile: 'reports/junit/TESTS-xunit.xml'
                                                                                                          },
                                                                                                      
                                                                                                          coverageReporter: {
                                                                                                            type: 'lcov',
                                                                                                            dir: 'reports',
                                                                                                            subdir: 'coverage'
                                                                                                          }
                                                                                                        })
                                                                                                      }
                                                                                                      

                                                                                                      Now my GULP FILE which is failing with karma.start() whenever I run the following node ./node_modules/gulp/bin/gulp.js test at the command prompt in VS Code Terminal

                                                                                                          var gulp = require('gulp');
                                                                                                          var karma = require('karma').server;
                                                                                                          var replace = require('gulp-replace');
                                                                                                      
                                                                                                          var postprocessLCOV = function() {
                                                                                                              return gulp.src('reports/coverage/lcov.info')
                                                                                                                  .pipe(replace('SF:.', 'SF:frontend-project'))
                                                                                                                  .pipe(gulp.dest('reports/coverage'));
                                                                                                          };
                                                                                                      
                                                                                                          gulp.task('test', function () {
                                                                                                              karma.start({
                                                                                                                  configFile: __dirname + '/src/test/js/karma.conf.ci.js'
                                                                                                              }, postprocessLCOV);
                                                                                                          });
                                                                                                      

                                                                                                      Of Note: My karma.conf.js and .ci.js are exactly the same so I don't have to post both files here.

                                                                                                      Finally, my package.json which shows everything I'm using. Whenever I added an new library, I have to delete the package.lock.json, after the new library is installed then re-run npm install.

                                                                                                      {
                                                                                                        "name": "global-comps",
                                                                                                        "version": "1.0.0",
                                                                                                        "description": "This is for the Navigator",
                                                                                                        "main": "qunit.js",
                                                                                                        "scripts": {
                                                                                                          "lint": "eslint '**/*.js'",
                                                                                                          "test": "qunit",
                                                                                                          "compodoc": "npx compodoc -p tsconfig.doc.json",
                                                                                                          "ng": "ng",
                                                                                                          "clean": "rm -rf node*",
                                                                                                          "ng-cli": "npm install --no-optional @angular/cli",
                                                                                                          "start": "ng serve --proxy-config proxy.config.json",
                                                                                                          "build": "ng build",
                                                                                                          "prod": "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod --output-hashing none && npm run test && npm run clean",
                                                                                                          "e2e": "ng e2e",
                                                                                                          "sonar": "sonar-scanner"
                                                                                                        },
                                                                                                        "repository": {
                                                                                                          "type": "git",
                                                                                                          "url": "somerepo.git"
                                                                                                        },
                                                                                                        "author": "Some Author",
                                                                                                        "license": "MIT",
                                                                                                        "dependencies": {
                                                                                                          "@angular/common": "~9.0.2",
                                                                                                          "@angular/compiler": "~9.0.2",
                                                                                                          "@angular/core": "~9.0.2",
                                                                                                          "@angular/platform-browser": "~9.0.2",
                                                                                                          "@angular/platform-browser-dynamic": "~9.0.2",
                                                                                                          "@angular/router": "~9.0.2",
                                                                                                          "@types/mocha": "^9.0.0",
                                                                                                          "JSONPath": "^0.11.2",
                                                                                                          "browserify": "^17.0.0",
                                                                                                          "common-js": "^0.3.8",
                                                                                                          "eslint-plugin-qunit": "^6.1.1",
                                                                                                          "jquery": "^3.4.1",
                                                                                                          "jquery-browserify": "^1.8.1",
                                                                                                          "jsdom": "^16.5.3",
                                                                                                          "junit": "^1.4.9",
                                                                                                          "karma-junit-reporter": "^2.0.1",
                                                                                                          "ng-mocks": "^11.10.1",
                                                                                                          "node": "^15.12.0",
                                                                                                          "npm-check-updates": "^11.5.13",
                                                                                                          "phantomjs": "^2.1.7",
                                                                                                          "qunit-reporter-junit": "^1.1.1",
                                                                                                          "qunit-reporter-lcov": "^1.0.2",
                                                                                                          "require": "^2.4.20",
                                                                                                          "rxjs": "~6.5.4",
                                                                                                          "tslib": "^1.10.0"
                                                                                                        },
                                                                                                        "devDependencies": {
                                                                                                          "@angular-devkit/build-angular": "^12.1.3",
                                                                                                          "@angular-devkit/build-webpack": "^0.1201.3",
                                                                                                          "@angular/compiler-cli": "~9.0.2",
                                                                                                          "@types/jasmine": "~3.5.0",
                                                                                                          "@types/jasminewd2": "~2.0.3",
                                                                                                          "@types/jsdom": "^16.2.13",
                                                                                                          "@types/node": "^12.11.1",
                                                                                                          "codelyzer": "^5.1.2",
                                                                                                          "grunt": "^1.3.0",
                                                                                                          "grunt-contrib-connect": "^3.0.0",
                                                                                                          "grunt-contrib-copy": "^1.0.0",
                                                                                                          "grunt-contrib-qunit": "^4.0.0",
                                                                                                          "grunt-git-authors": "^3.2.0",
                                                                                                          "grunt-search": "^0.1.8",
                                                                                                          "gulp": "^4.0.2",
                                                                                                          "gulp-replace": "^1.1.3",
                                                                                                          "jasmine-core": "~3.5.0",
                                                                                                          "jasmine-spec-reporter": "~4.2.1",
                                                                                                          "karma": "^6.3.2",
                                                                                                          "karma-chrome-launcher": "^3.1.0",
                                                                                                          "karma-coverage": "^2.0.3",
                                                                                                          "karma-coverage-istanbul-reporter": "^3.0.3",
                                                                                                          "karma-jasmine": "^4.0.1",
                                                                                                          "karma-jasmine-html-reporter": "^1.7.0",
                                                                                                          "karma-jasmine-jquery-2": "^0.1.1",
                                                                                                          "karma-mocha-reporter": "^2.2.5",
                                                                                                          "karma-phantomjs-launcher": "^1.0.4",
                                                                                                          "karma-qunit": "^4.1.2",
                                                                                                          "karma-sonarqube-unit-reporter": "0.0.23",
                                                                                                          "karma-webpack": "^5.0.0",
                                                                                                          "protractor": "~5.4.3",
                                                                                                          "puppeteer": "^1.20.0",
                                                                                                          "sonar-scanner": "^3.1.0",
                                                                                                          "sonarqube-scanner": "~2.7.0",
                                                                                                          "ts-node": "~8.3.0",
                                                                                                          "typescript": "~3.7.5"
                                                                                                        },
                                                                                                        "global": "window"
                                                                                                      }
                                                                                                      

                                                                                                      So, that's where I'm at.

                                                                                                      UPDATE!

                                                                                                      So, I've abandoned GULP and got Karma to work.

                                                                                                      But in SONARQUBE, what I'm getting is 0% coverage because Karma is NOT creating the lcov.info file even though it's creating the coverage directory and subsequent files.

                                                                                                      OF NOTE: I can run my tests in the browser in QUNIT and see them succeed or fail in either case.

                                                                                                      BUT I need KARMA to create the lcov.info file with the tests I've created in my .js file. Since this is not Angular but just pure JavaScript, that's where I'm stuck.

                                                                                                      Here's a screen shot of my SONARQUBE Coverage to show you what I'm getting.

                                                                                                      I'd really like some help here.

                                                                                                      Again, here are the Two SIMPLE test files that I'm running using QUNIT that work but are NOT when I run them in KARMA.

                                                                                                      Thank you everyone for your continued support.

                                                                                                          describe('A Suite for a simple test', () => {
                                                                                                      
                                                                                                              var a;
                                                                                                      
                                                                                                              it('and so it is a spec', () => {
                                                                                                                  a = true;
                                                                                                                  expect(a).toBe(true);
                                                                                                              });
                                                                                                      
                                                                                                              it('2 plus 2 should be 4', () => {
                                                                                                                  const result = add(2, 2);
                                                                                                      
                                                                                                                  expect(result).toBe(4);
                                                                                                      
                                                                                                              });
                                                                                                      
                                                                                                          });
                                                                                                      
                                                                                                          describe('Test case 1', () => {
                                                                                                              var zipcodevalue = '';
                                                                                                      
                                                                                                              const test1 = sendToTest1;
                                                                                                      
                                                                                                              console.log('Test 1 is: ', test1);
                                                                                                      
                                                                                                              beforeEach(function () {
                                                                                                                  zipToTestCase.call(this, {
                                                                                                                      assert: assert,
                                                                                                                      zipcodevalue: '98237',
                                                                                                                      expected: "Success"
                                                                                                                  });
                                                                                                              });
                                                                                                      
                                                                                                              function zipToTestCase() {
                                                                                                      
                                                                                                                  if (isNaN(zipcodevalue === false)) {
                                                                                                                      expect(zipcodevalue, '98237', 'string value and hard code value are NOT equal', function (callback) {
                                                                                                                          callback(zipcodevalue);
                                                                                                                      });
                                                                                                                  } else {
                                                                                                                      expect(zipcodevalue, '98237', 'string value and hard code value are equal', function (callback) {
                                                                                                                          callback(zipcodevalue);
                                                                                                                      });
                                                                                                                  }
                                                                                                      
                                                                                                              }
                                                                                                      
                                                                                                              it('test for Valid ZipCode', () => {
                                                                                                                  expect(zipcodevalue).toBeTruthy();
                                                                                                              })
                                                                                                      
                                                                                                              it('test for INValid ZipCode', () => {
                                                                                                                  expect(zipcodevalue).toBeFalsy();
                                                                                                              })
                                                                                                      
                                                                                                          });
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2021-Aug-04 at 13:43

                                                                                                      I found the answer here with this article!

                                                                                                      https://sourcedcode.com/blog/aem/how-to-write-javascript-unit-tests-for-aem-client-libraries-with-jest

                                                                                                      This is EXACTLY what I needed and the results are PERFECT!

                                                                                                      Source https://stackoverflow.com/questions/68594875

                                                                                                      QUESTION

                                                                                                      No tests found after splitting tasks out into separate jobs
                                                                                                      Asked 2021-May-17 at 23:44

                                                                                                      I am trying to refactor my build pipeline by splitting some tasks out into separate jobs for extensibility.

                                                                                                      The following works perfectly and the tests are found and ran without issue.

                                                                                                      stages:
                                                                                                        - stage: build_test_publish
                                                                                                          displayName: Build
                                                                                                          pool:
                                                                                                            vmImage: "windows-latest"
                                                                                                          variables:
                                                                                                            solution: "**/SolutionName.sln"
                                                                                                            buildPlatform: "Any CPU"
                                                                                                            buildConfiguration: "Release"
                                                                                                          jobs:
                                                                                                            - job: build_publish_artifacts
                                                                                                              displayName: "Build, test and publish artifacts"
                                                                                                              steps:
                                                                                                                - task: NuGetToolInstaller@1
                                                                                                                - task: NuGetCommand@2
                                                                                                                  inputs:
                                                                                                                    command: "restore"
                                                                                                                    restoreSolution: "**/*.sln"
                                                                                                                    feedsToUse: "select"
                                                                                                                    vstsFeed: "xxx"
                                                                                                      
                                                                                                                - task: VSBuild@1
                                                                                                                  inputs:
                                                                                                                    solution: "$(solution)"
                                                                                                                    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
                                                                                                                    platform: "$(buildPlatform)"
                                                                                                                    configuration: "$(buildConfiguration)"
                                                                                                      
                                                                                                                - task: VSTest@2
                                                                                                                  inputs:
                                                                                                                    platform: '$(buildPlatform)'
                                                                                                                    configuration: '$(buildConfiguration)'
                                                                                                                    runInParallel: false
                                                                                                                    codeCoverageEnabled: true
                                                                                                                    testAssemblyVer2: |
                                                                                                                       **\*test*.dll
                                                                                                                       !**\ProjectName.IntegrationTests.dll
                                                                                                                       !**\*TestAdapter.dll
                                                                                                                       !**\obj\**
                                                                                                                    searchFolder: '$(System.DefaultWorkingDirectory)'
                                                                                                      

                                                                                                      However after splitting it out like below I get the following output where no tests can be found.

                                                                                                      stages:
                                                                                                        - stage: build_test_publish
                                                                                                          displayName: Build, test and publish artifacts
                                                                                                          pool:
                                                                                                            vmImage: "windows-latest"
                                                                                                          variables:
                                                                                                            solution: "**/SolutionName.sln"
                                                                                                            buildPlatform: "Any CPU"
                                                                                                            buildConfiguration: "Release"
                                                                                                          jobs: 
                                                                                                            - job: build
                                                                                                              displayName: "Build"
                                                                                                              steps:
                                                                                                                - task: NuGetToolInstaller@1
                                                                                                                - task: NuGetCommand@2
                                                                                                                  inputs:
                                                                                                                    command: "restore"
                                                                                                                    restoreSolution: "**/*.sln"
                                                                                                                    feedsToUse: "select"
                                                                                                                    vstsFeed: "xxx"
                                                                                                                - task: VSBuild@1
                                                                                                                  inputs:
                                                                                                                    solution: "$(solution)"
                                                                                                                    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
                                                                                                                    platform: "$(buildPlatform)"
                                                                                                                    configuration: "$(buildConfiguration)"
                                                                                                                      
                                                                                                      
                                                                                                            - job: test
                                                                                                              displayName: Run unit tests
                                                                                                              dependsOn: build
                                                                                                              steps:
                                                                                                                - task: VSTest@2
                                                                                                                  inputs:
                                                                                                                    platform: '$(buildPlatform)'
                                                                                                                    configuration: '$(buildConfiguration)'
                                                                                                                    runInParallel: false
                                                                                                                    codeCoverageEnabled: true
                                                                                                                    testAssemblyVer2: |
                                                                                                                       **\*test*.dll
                                                                                                                       !**\ProjectName.IntegrationTests.dll
                                                                                                                       !**\*TestAdapter.dll
                                                                                                                       !**\obj\**
                                                                                                                    searchFolder: '$(System.DefaultWorkingDirectory)'
                                                                                                      
                                                                                                      Starting: VSTest
                                                                                                      ==============================================================================
                                                                                                      Task         : Visual Studio Test
                                                                                                      Description  : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
                                                                                                      Version      : 2.170.1
                                                                                                      Author       : Microsoft Corporation
                                                                                                      Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/test/vstest
                                                                                                      ==============================================================================
                                                                                                      SystemVssConnection exists true
                                                                                                      SystemVssConnection exists true
                                                                                                      Running tests using vstest.console.exe runner.
                                                                                                      ======================================================
                                                                                                      Test selector : Test assemblies
                                                                                                      Test filter criteria : null
                                                                                                      Search folder : D:\a\1\s
                                                                                                      Action when minimum tests threshold not met : donothing
                                                                                                      Minimum tests expected to be run: 0
                                                                                                      VisualStudio version selected for test execution : latest
                                                                                                      Attempting to find vstest.console from a visual studio installation with version [16.0,17.0).
                                                                                                      Run in parallel : false
                                                                                                      Run in isolation : false
                                                                                                      Path to custom adapters : null
                                                                                                      Other console options : null
                                                                                                      Code coverage enabled : true
                                                                                                      Diagnostics enabled : false
                                                                                                      SystemVssConnection exists true
                                                                                                      Run the tests locally using vstest.console.exe
                                                                                                      ========================================================
                                                                                                      Source filter: **\*test*.dll,!**\ProjectName.IntegrationTests.dll,!**\*TestAdapter.dll,!**\obj\**
                                                                                                      ##[warning]No test sources found matching the given filter '**\*test*.dll,!**\ProjectName.IntegrationTests.dll,!**\*TestAdapter.dll,!**\obj\**'
                                                                                                      Finishing: VSTest
                                                                                                      
                                                                                                      

                                                                                                      Why does this happen and what should I change or rethink?

                                                                                                      **Edit Seems like it might be because each jobs uses it's own agent to run the tasks in it's job.

                                                                                                      https://docs.microsoft.com/en-us/azure/devops/pipelines/get-started/key-pipelines-concepts?view=azure-devops

                                                                                                      I would still like to know if something like this is possible in order to start test runs with different environment variables

                                                                                                      ANSWER

                                                                                                      Answered 2021-May-17 at 23:44

                                                                                                      DLL's produced by

                                                                                                                - task: VSBuild@1
                                                                                                                  inputs:
                                                                                                                    solution: "$(solution)"
                                                                                                                    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
                                                                                                                    platform: "$(buildPlatform)"
                                                                                                                    configuration: "$(buildConfiguration)"
                                                                                                      

                                                                                                      are not shared between jobs out of the box. Behind the scene splitting task you run VSBuild and VSTask on different machines. There is no much sense of doing that - I mean splitting these two tasks.

                                                                                                      However, if you still want to do this you need to publish artifact and download it in next job.

                                                                                                      Source https://stackoverflow.com/questions/67567079

                                                                                                      QUESTION

                                                                                                      Error: 'ReferenceError: pauseTest is not defined' in integration tests with moduleForComponent syntax
                                                                                                      Asked 2020-Nov-19 at 19:17

                                                                                                      The pauseTest() function from ember-qunit does not work as expected in Integration tests with the old syntax

                                                                                                      import { moduleForComponent, test } from 'ember-qunit';
                                                                                                      import hbs from 'htmlbars-inline-precompile';
                                                                                                      
                                                                                                      moduleForComponent('my-component, 'Integration | Component | MyComponent', {
                                                                                                        integration: true
                                                                                                      });
                                                                                                      
                                                                                                      test('it renders', function(assert) {
                                                                                                        return pauseTest();
                                                                                                        this.render(hbs`{{my-component}}/>`);
                                                                                                        ...
                                                                                                      }
                                                                                                      

                                                                                                      Failed:

                                                                                                      Died on test #1     at Module.callback (http://localhost:4200/assets/tests.js:118959:24)
                                                                                                      at Module.exports (http://localhost:4200/assets/vendor.js:111:32)
                                                                                                      at requireModule (http://localhost:4200/assets/vendor.js:32:18)
                                                                                                      at EmberExamQUnitTestLoader. (http://localhost:4200/assets/test-support.js:29031:11)
                                                                                                        at EmberExamQUnitTestLoader.require (http://localhost:4200/assets/test-support.js:29021:27)
                                                                                                      at http://localhost:4200/assets/test-support.js:29545:90
                                                                                                        at Array.forEach (): pauseTest is not defined@ 698 ms
                                                                                                        Source:
                                                                                                        ReferenceError: pauseTest is not defined
                                                                                                        at Object. (http://localhost:4200/assets/tests.js:118960:5)
                                                                                                          at runTest (http://localhost:4200/assets/test-support.js:20889:30)
                                                                                                          at Test.run (http://localhost:4200/assets/test-support.js:20875:6)
                                                                                                          at http://localhost:4200/assets/test-support.js:21096:12
                                                                                                          at advanceTaskQueue (http://localhost:4200/assets/test-support.js:20488:6)
                                                                                                          at Object.advance (http://localhost:4200/assets/test-support.js:20469:4)
                                                                                                          at begin (http://localhost:4200/assets/test-support.js:22241:20)
                                                                                                          at http://localhost:4200/assets/test-support.js:21483:6
                                                                                                      

                                                                                                      It's working fine in Acceptance tests, because of:

                                                                                                      // ./tests/helpers/start-app.js
                                                                                                      export default function startApp(attrs) {
                                                                                                        ...
                                                                                                          application.injectTestHelpers();
                                                                                                        ...
                                                                                                      }
                                                                                                      

                                                                                                      How to make it works in Integration tests?

                                                                                                      Note: In modern syntax, it's working fine too:

                                                                                                      import { module, test } from 'qunit';
                                                                                                      import { setupRenderingTest } from 'ember-qunit';
                                                                                                      import { render } from '@ember/test-helpers';
                                                                                                      import hbs from 'htmlbars-inline-precompile';
                                                                                                      
                                                                                                      module('Integration | Component | MyComponent', function(hooks) {
                                                                                                        test('it renders', async function(assert) {
                                                                                                          return this.pauseTest();
                                                                                                          await render(hbs`{{my-component}}/>`);
                                                                                                        });
                                                                                                      }
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2020-Nov-19 at 19:17

                                                                                                      workaround:

                                                                                                      import { moduleForComponent, test } from 'ember-qunit';
                                                                                                      import hbs from 'htmlbars-inline-precompile';
                                                                                                      import Ember from 'ember';
                                                                                                      
                                                                                                      moduleForComponent('my-component, 'Integration | Component | MyComponent', {
                                                                                                        integration: true
                                                                                                      });
                                                                                                      
                                                                                                      test('it renders', function(assert) {
                                                                                                        return Ember.Test._helpers.pauseTest.method();
                                                                                                        this.render(hbs`{{my-component}}/>`);
                                                                                                        ...
                                                                                                      }
                                                                                                      
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/64918528

                                                                                                      QUESTION

                                                                                                      Use only 1 date from daily dataset in R
                                                                                                      Asked 2020-Sep-14 at 06:40

                                                                                                      I have a data set, which is a daily data set I want just to select 1 day as a month value, not the average or mean of the month. So I want to just use 2000131 to be in the data set and the same followed with all other months (last or second last date in the dataset). Kindly help. Thanks in advance.

                                                                                                          structure(list(X = 1:6, gvkey = c(7041L, 7041L, 7041L, 7041L, 
                                                                                                      7041L, 7041L), datadate = c(20000103L, 20000104L, 20000105L, 
                                                                                                      20000106L, 20000111L, 20000112L), cshoc = c(4.2e+07, 4.2e+07, 
                                                                                                      4.2e+07, 4.2e+07, 4.2e+07, 4.2e+07), cshtrd = c(112000, 637000, 
                                                                                                      241000, 251000, 224000, 194000), prccd = c(3.86, 4.28, 4, 4.04, 
                                                                                                      4, 3.96), prchd = c(3.86, 4.6, 4.22, 4.26, 4.26, 4.04), prcld = c(3.3, 
                                                                                                      3.86, 3.9, 3.96, 4, 3.9), prcstd = c(10L, 10L, 10L, 10L, 10L, 
                                                                                                      10L), qunit = c(1L, 1L, 1L, 1L, 1L, 1L), cheqv = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), cheqvgross = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), div = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divd = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divdgross = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divdnet = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divdtm = c("", 
                                                                                                      "", "", "", "", ""), divgross = c(NA_real_, NA_real_, NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_), divnet = c(NA_real_, NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_), divrc = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divrcgross = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divrcnet = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divsp = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divspgross = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divspnet = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divsptm = c("", 
                                                                                                      "", "", "", "", ""), anncdate = c(NA_integer_, NA_integer_, NA_integer_, 
                                                                                                      NA_integer_, NA_integer_, NA_integer_), cheqvpaydate = c(NA_integer_, 
                                                                                                      NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
                                                                                                      ), divdpaydate = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                      NA_integer_, NA_integer_), divrcpaydate = c(NA_integer_, NA_integer_, 
                                                                                                      NA_integer_, NA_integer_, NA_integer_, NA_integer_), divsppaydate = c(NA_integer_, 
                                                                                                      NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
                                                                                                      ), paydate = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                      NA_integer_, NA_integer_), recorddate = c(NA_integer_, NA_integer_, 
                                                                                                      NA_integer_, NA_integer_, NA_integer_, NA_integer_), split = c(NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), splitf = c("", 
                                                                                                      "", "", "", "", ""), trfd = c(1.05474854, 1.05474854, 1.05474854, 
                                                                                                      1.05474854, 1.05474854, 1.05474854), monthend = c(0L, 0L, 0L, 
                                                                                                      0L, 0L, 0L), fyrc = c(3L, 3L, 3L, 3L, 3L, 3L), ggroup = c(2010L, 
                                                                                                      2010L, 2010L, 2010L, 2010L, 2010L), gind = c(201070L, 201070L, 
                                                                                                      201070L, 201070L, 201070L, 201070L), gsector = c(20L, 20L, 20L, 
                                                                                                      20L, 20L, 20L), gsubind = c(20107010L, 20107010L, 20107010L, 
                                                                                                      20107010L, 20107010L, 20107010L), naics = c(999990L, 999990L, 
                                                                                                      999990L, 999990L, 999990L, 999990L), sic = c(9995L, 9995L, 9995L, 
                                                                                                      9995L, 9995L, 9995L), spcindcd = c(400L, 400L, 400L, 400L, 400L, 
                                                                                                      400L), spcseccd = c(970L, 970L, 970L, 970L, 970L, 970L), ipodate = c(19920103L, 
                                                                                                      19920103L, 19920103L, 19920103L, 19920103L, 19920103L)), row.names = c(NA, 
                                                                                                      6L), class = "data.frame")
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2020-Sep-14 at 06:40

                                                                                                      Try using this :

                                                                                                      Change the date values into actual date and extract year-month value from it. arrange the data based on Date and for each month select the last value of the month.

                                                                                                      library(dplyr)
                                                                                                      
                                                                                                      newdf3 <- newdata2 %>%
                                                                                                                 mutate(Date = as.Date(as.character(datadate), '%Y%m%d'),
                                                                                                                        month_year = format(Date, '%Y%m')) %>%
                                                                                                                 arrange(desc(Date)) %>%
                                                                                                                 group_by(gvkey, month_year) %>%
                                                                                                                 slice(1L) %>%
                                                                                                                 ungroup %>%
                                                                                                                 arrange(gvkey)
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/63877498

                                                                                                      QUESTION

                                                                                                      How to keep data constant after merging from 2 or more csv file in R
                                                                                                      Asked 2020-Sep-11 at 03:30

                                                                                                      I have a big data CSV file. I managed to merge them into one CSV file. Now when I read the file its is not consistent inflow. For example :

                                                                                                      file1 CSV: id date 
                                                                                                                 21 2001
                                                                                                                 21 2002
                                                                                                                 21 2003
                                                                                                                 22 2001
                                                                                                                 22 2001
                                                                                                                 22 2002
                                                                                                      file2 CSV: 21 2006
                                                                                                                 21 2005
                                                                                                                 21 2007
                                                                                                                 22 2006
                                                                                                                 22 2006
                                                                                                      

                                                                                                      and so on. Now when I merge all files in one CSV i want output like

                                                                                                         id date 
                                                                                                         21 2001
                                                                                                         21 2002
                                                                                                         21 2003
                                                                                                         21 2006
                                                                                                         21 2005
                                                                                                         21 2007
                                                                                                         22 2001
                                                                                                         22 2001
                                                                                                         22 2002
                                                                                                         22 2006
                                                                                                         22 2006
                                                                                                      

                                                                                                      Code:

                                                                                                      All <- lapply(filenames_list,function(filename){
                                                                                                        print(paste("Merging",filename,sep = " "))
                                                                                                        read.csv(filename)
                                                                                                      })
                                                                                                      
                                                                                                      df <- data.frame(do.call(rbind.data.frame, All))
                                                                                                      write.csv(df,merge_file_name)
                                                                                                      

                                                                                                      this is the code I did to merge all files in one CSV. Kindly help me to keep them in an organized pattern.

                                                                                                      dput(head(newdata1,10))
                                                                                                      structure(list(X = 1:10, gvkey = c(7041L, 7041L, 7041L, 7041L, 
                                                                                                      7041L, 7041L, 7041L, 7041L, 7041L, 7041L), datadate = c(20000103L, 
                                                                                                      20000104L, 20000105L, 20000106L, 20000111L, 20000112L, 20000113L, 
                                                                                                      20000114L, 20000117L, 20000118L), cshoc = c(4.2e+07, 4.2e+07, 
                                                                                                      4.2e+07, 4.2e+07, 4.2e+07, 4.2e+07, 4.2e+07, 4.2e+07, 4.2e+07, 
                                                                                                      4.2e+07), cshtrd = c(112000, 637000, 241000, 251000, 224000, 
                                                                                                      194000, 175000, 217000, 307000, 326000), prccd = c(3.86, 4.28, 
                                                                                                      4, 4.04, 4, 3.96, 3.92, 3.96, 4.06, 4.14), prchd = c(3.86, 4.6, 
                                                                                                      4.22, 4.26, 4.26, 4.04, 4.1, 4.02, 4.2, 4.3), prcld = c(3.3, 
                                                                                                      3.86, 3.9, 3.96, 4, 3.9, 3.92, 3.88, 4, 4.02), prcstd = c(10L, 
                                                                                                      10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), qunit = c(1L, 1L, 
                                                                                                      1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), cheqv = c(NA_real_, NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                      NA_real_), cheqvgross = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                      NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), 
                                                                                                          div = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divd = c(NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_), divdgross = c(NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_), divdnet = c(NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_), divdtm = c("", "", "", "", "", "", "", "", "", 
                                                                                                          ""), divgross = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
                                                                                                          ), divnet = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divrc = c(NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_), divrcgross = c(NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_), divrcnet = c(NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_), divsp = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
                                                                                                          ), divspgross = c(NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_
                                                                                                          ), divspnet = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_), divsptm = c("", 
                                                                                                          "", "", "", "", "", "", "", "", ""), anncdate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), cheqvpaydate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), divdpaydate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), divrcpaydate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), divsppaydate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), paydate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), recorddate = c(NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_, 
                                                                                                          NA_integer_, NA_integer_, NA_integer_, NA_integer_), split = c(NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, 
                                                                                                          NA_real_, NA_real_, NA_real_), splitf = c("", "", "", "", 
                                                                                                          "", "", "", "", "", ""), trfd = c(1.05474854, 1.05474854, 
                                                                                                          1.05474854, 1.05474854, 1.05474854, 1.05474854, 1.05474854, 
                                                                                                          1.05474854, 1.05474854, 1.05474854), monthend = c(0L, 0L, 
                                                                                                          0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), fyrc = c(3L, 3L, 3L, 3L, 
                                                                                                          3L, 3L, 3L, 3L, 3L, 3L), ggroup = c(2010L, 2010L, 2010L, 
                                                                                                          2010L, 2010L, 2010L, 2010L, 2010L, 2010L, 2010L), gind = c(201070L, 
                                                                                                          201070L, 201070L, 201070L, 201070L, 201070L, 201070L, 201070L, 
                                                                                                          201070L, 201070L), gsector = c(20L, 20L, 20L, 20L, 20L, 20L, 
                                                                                                          20L, 20L, 20L, 20L), gsubind = c(20107010L, 20107010L, 20107010L, 
                                                                                                          20107010L, 20107010L, 20107010L, 20107010L, 20107010L, 20107010L, 
                                                                                                          20107010L), naics = c(999990L, 999990L, 999990L, 999990L, 
                                                                                                          999990L, 999990L, 999990L, 999990L, 999990L, 999990L), sic = c(9995L, 
                                                                                                          9995L, 9995L, 9995L, 9995L, 9995L, 9995L, 9995L, 9995L, 9995L
                                                                                                          ), spcindcd = c(400L, 400L, 400L, 400L, 400L, 400L, 400L, 
                                                                                                          400L, 400L, 400L), spcseccd = c(970L, 970L, 970L, 970L, 970L, 
                                                                                                          970L, 970L, 970L, 970L, 970L), ipodate = c(19920103L, 19920103L, 
                                                                                                          19920103L, 19920103L, 19920103L, 19920103L, 19920103L, 19920103L, 
                                                                                                          19920103L, 19920103L)), row.names = c(NA, 10L), class = "data.frame")
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2020-Sep-11 at 03:30

                                                                                                      If I understand your ideal outcome correctly, you want to order the data.frame df by the column ID and then save this as a csv file. If so, in your code you can add a line using order() and sort by id in ascending order and then save that data frame. By putting order inside the square brackets [] it retains the rest of your data. By putting order before the comma , inside the brackets, the data becomes ordered by the row values.

                                                                                                      Instead of:

                                                                                                      df <- data.frame(do.call(rbind.data.frame, All))
                                                                                                      write.csv(df,merge_file_name)
                                                                                                      

                                                                                                      Add the line with order:

                                                                                                      df <- data.frame(do.call(rbind.data.frame, All))
                                                                                                      new_df <- df[order(df$id),] 
                                                                                                      write.csv(new_df,merge_file_name)
                                                                                                      

                                                                                                      For a full example:

                                                                                                      # Create two data frames
                                                                                                      df1 <- data.frame(gvkey = c(1:6),
                                                                                                                        dat = runif(6))
                                                                                                      
                                                                                                      df2 <- data.frame(gvkey = c(1:6),
                                                                                                                        dat = runif(6))
                                                                                                      
                                                                                                      # bind them by the rows 
                                                                                                      df <- rbind(df1, df2)
                                                                                                      
                                                                                                      # order by gvkey
                                                                                                      new_df <- df[order(df$gvkey),] 
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/63825629

                                                                                                      QUESTION

                                                                                                      Testing function which checks if cookies are enabled with Qunit
                                                                                                      Asked 2020-Aug-18 at 21:14

                                                                                                      I have the following function which checks if cookies are enabled in a user's browser:

                                                                                                      CookiesEnabled: function() {
                                                                                                          var cookieEnabled = navigator.cookieEnabled;
                                                                                                          if (!cookieEnabled) {
                                                                                                              document.cookie = "test_cookie";
                                                                                                              cookieEnabled = document.cookie.indexOf("test_cookie") != -1;
                                                                                                          }
                                                                                                      
                                                                                                          return cookieEnabled;
                                                                                                      },
                                                                                                      

                                                                                                      I want to unit test that this works using Sinon/Qunit but am unsure of how to approach this properly as I am not very experienced using Sinon or QUnit. Here is my attempt at putting together a test:

                                                                                                      QUnit.test("CookiesEnabled - returns true if user has enabled cookies in their browser", function (assert) {
                                                                                                          sinon.stub(CookieHelper, "CookiesEnabled")
                                                                                                               .callsFake(function () {});
                                                                                                      
                                                                                                          var result = CookieHelper.CookiesEnabled();
                                                                                                      
                                                                                                          Assert.Equal(result, true);
                                                                                                      
                                                                                                          CookieHelper.CookiesEnabled.restore();
                                                                                                      });
                                                                                                      

                                                                                                      Please can anyone point me in the right direction for unit testing this method using Qunit and Sinon? Thank you.

                                                                                                      UPDATED ATTEMPT:

                                                                                                      QUnit.test("CookiesEnabled - returns true if user has enabled cookies in their browser", function (assert) {
                                                                                                          sinon.stub(navigator, "cookieEnabled").callsFake(function () {
                                                                                                              return true;
                                                                                                          });
                                                                                                      
                                                                                                          var result = CookieHelper.CookiesEnabled();
                                                                                                      
                                                                                                          assert.equal(result, true);
                                                                                                      
                                                                                                      });
                                                                                                      

                                                                                                      ANSWER

                                                                                                      Answered 2020-Aug-18 at 21:14

                                                                                                      As mentioned, window.navigator is readonly. There are some things you could try to fake out the browser, but really, you should just inject the properties you're interested in for the function to use. This way you can override the browser setting or test it! Notice the addition of two arguments (since you also need to bypass your double-checking of cookie setting).

                                                                                                      The additional flag argument is a boolean that essentially tells the function what the value of cookieEnabled should be (versus using navigator.cookieEnabled). However, if that parameter is missing, the code will use the browser setting. In other words, it's a way to "inject" the value you want, very useful in testing. This isn't ideal, but not much else you can without a lot more work and mocking (using a headless browser with cookies disabled).

                                                                                                      Here's a jsfiddle of this working: https://jsfiddle.net/e5mtpboy/

                                                                                                      CookiesEnabled: function(flag, bypassTest) {
                                                                                                          var cookieEnabled = typeof(flag) === 'boolean' ? flag : navigator.cookieEnabled;
                                                                                                          if (!cookieEnabled && !bypassTest) {
                                                                                                              document.cookie = "test_cookie";
                                                                                                              cookieEnabled = document.cookie.indexOf("test_cookie") != -1;
                                                                                                          }
                                                                                                      
                                                                                                          return cookieEnabled;
                                                                                                      }
                                                                                                      

                                                                                                      Then in your tests:

                                                                                                      QUnit.test("CookiesEnabled - returns true if user has enabled cookies in their browser", function (assert) {
                                                                                                          var result = CookieHelper.CookiesEnabled(true);
                                                                                                          assert.equal(result, true);
                                                                                                      });
                                                                                                      
                                                                                                      QUnit.test("CookiesEnabled - returns true if user has disabled cookies, but we can still set one", function (assert) {
                                                                                                          var result = CookieHelper.CookiesEnabled(false);
                                                                                                          assert.equal(result, true);
                                                                                                      });
                                                                                                      
                                                                                                      QUnit.test("CookiesEnabled - returns false if browser does not support cookies", function (assert) {
                                                                                                          var result = CookieHelper.CookiesEnabled(false, true);
                                                                                                          assert.equal(result, false);
                                                                                                      });
                                                                                                      

                                                                                                      Source https://stackoverflow.com/questions/63471777

                                                                                                      Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                                      Vulnerabilities

                                                                                                      No vulnerabilities reported

                                                                                                      Install qunit

                                                                                                      You can install using 'npm i qunitjs-2' or download it from GitHub, npm.

                                                                                                      Support

                                                                                                      API documentationGuides how-toBrowser supportIntegrations
                                                                                                      Find more information at:
                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit
                                                                                                      CLONE
                                                                                                    • HTTPS

                                                                                                      https://github.com/qunitjs/qunit.git

                                                                                                    • CLI

                                                                                                      gh repo clone qunitjs/qunit

                                                                                                    • sshUrl

                                                                                                      git@github.com:qunitjs/qunit.git

                                                                                                    • Share this Page

                                                                                                      share link

                                                                                                      Explore Related Topics

                                                                                                      Consider Popular Runtime Evironment Libraries

                                                                                                      Try Top Libraries by qunitjs

                                                                                                      node-qunit

                                                                                                      by qunitjsJavaScript

                                                                                                      qunitjs.com

                                                                                                      by qunitjsJavaScript

                                                                                                      api.qunitjs.com

                                                                                                      by qunitjsCSS

                                                                                                      jekyll-theme-amethyst

                                                                                                      by qunitjsHTML

                                                                                                      Compare Runtime Evironment Libraries with Highest Support

                                                                                                      node

                                                                                                      by nodejs

                                                                                                      electron

                                                                                                      by electron

                                                                                                      Rocket.Chat

                                                                                                      by RocketChat

                                                                                                      TypeScript

                                                                                                      by microsoft

                                                                                                      express

                                                                                                      by expressjs

                                                                                                      Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                                      Find more libraries
                                                                                                      Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                                      Save this library and start creating your kit