qunit | 🔮 An easy-to-use JavaScript unit testing framework | Runtime Evironment library
kandi X-RAY | qunit Summary
Support
Quality
Security
License
Reuse
- 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 .
qunit Key Features
qunit Examples and Code Snippets
Trending Discussions on qunit
Trending Discussions on qunit
QUESTION
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:111. 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
QUESTION
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:05Finally, I fix my issue by downgrading the node version from 17 to 16.
QUESTION
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:29You 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);
QUESTION
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:33How 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);
});
});
QUESTION
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:43I found the answer here with this article!
This is EXACTLY what I needed and the results are PERFECT!
QUESTION
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.
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:44DLL'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.
QUESTION
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:17workaround:
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}}/>`);
...
}
QUESTION
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:40Try 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)
QUESTION
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:30If 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),]
QUESTION
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:14As 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);
});
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install qunit
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
Save this library and start creating your kit
Share this Page