Open helabenkhalfallah opened 5 years ago
Your Karma version seems to be very old. Did you add all the error output? It was expected more details have been outputted. Could you provide a sample project to reproduce this error? Thank you!
I will try using a more recent version of karma, thank you :) :)
Great! Let me know if it works with a newer Karma version. Meanwhile, I'll try to find out the minimal required version. I think I should have made it clear in the README instructions.
Hello @fadc80 I changed karma version to "karma": "=4.0.0", but I have the same issue. :(
Maybe you are not defining basePath
and/or filePattern
corretcly. According to the provided configuration, your project structure should look like this:
yourProject [folder] --> karma.conf.js [configuration file] --> test [basePath] ----> componetA [folder] ------> componentA.ts [source file] ------> componentA.spec.ts [filePattern match]
Verify your karma.conf.js
file and test
folder are inside the same folder. Additionally, be sure all test files are stored under the test
folder or subfolders recursively.
The issue occurs every time when parseTestFile()
processes tests or test suites which are skipped. This means while describe()
is matched, describe.skip()
isn't. Same is true for it
.
After some debugging I figured that the root cause lied within this regular expression:
((describe)|(it))\s*\(\s*((?<![\\])[\`\'\"])((?:.(?!(?<![\\])\4))*.?)\4
onSpecComplete
defined in index.js
checks if a test is successful, skipped or faileddescribe.skip()
, this.specSkipped
is invoked and callspathfinder.testFile
, which iterates over all matched files and invokesexist()
for each file but returns undefined
because existDescribe
looks for a property describe
on an object which was never createdThe method parseTestFile()
iterates over the result array of exec
and assigns the values of result[2] || result[3];
to type
.
As the regex doesn't match describe.skip()
, type
is undefined
.
Therefore paths[path] = { describe: [], it: [] };
is never created, exist
(existDescribe
) will fail which results in Test file path not found!
function testFile(paths, describe, it) {
var testFile = Object.keys(paths).find(path =>
exist(paths, path, describe, it));
if (testFile === undefined) {
logger.error('Test file path not found! %s | %s | %s',
JSON.stringify(paths), describe, it);
}
return testFile;
}
I fixed this issue in #24 by slightly changing the regular expression. It now matches:
describe.skip
describe.only
fdescribe
xdescribe
it.skip
it.only
fit
xit
All of this is afaik valid at least for Mocha
and Jasmine
((\S{0,2}describe?[^(]+)|(\s\S{0,2}it?[^(]+))\s*\(\s*((?<![\\])[`'"])((?:.(?!(?<![\\])\4))*.?)\4
You can see it in action here: https://regex101.com/r/HUyh3u/1
This regex will match things like describe.lorem
or describeLore()
too. I guess this shouldn't be a problem because Jasmine
or Mocha
won't execute it either.
Hello @gearsdigital , your fix seems good for me, I will try to modify on my local and let you in ;) Thanks. :)
@helabenkhalfallah I wonder if you can confirm to have skipped tests on your setup.
As I didn't have a sample project to reproduce it, I was just trying to guess what was wrong. I'm going to check your PR. Thank you.
@fadc80 Do you need a sample project to verify? I can provide mine if you want...
It would be good! :+1:
@all-contributors please add @helabenkhalfallah as a contributor for bug.
@fadc80
I've put up a pull request to add @helabenkhalfallah! :tada:
Hello, I have not skipped tests on my configuration :
module.exports = function (config) {
require("awt-unit-testing")(config, require("./webpack.config.js"));
config.set({
sonarqubeReporter: {
basePath: 'test', // test files folder
filePattern: '**/*spec.ts', // test files glob pattern
encoding: 'utf-8', // test files encoding
outputFolder: 'target/report-tests', // report destination
legacyMode: false, // report for Sonarqube < 6.2 (disabled)
reportName: "karma-sonar-test.xml"
},
reporters: ['sonarqube']
});
};
I have only this and when I run : ERROR: Please, report issue => Test file path not found! {}
I use the version 1.3.0.
Thank you so much for your help :)
A test example :
describe("path", function () {
/**
* Test jasmine
*/
it("first test", function () {
expect(true).not.toBe(false);
});
/**
* Test jasmine
*/
it("second test", function () {
expect(true).toBe(true);
});
});
@helabenkhalfallah Could you please try to delete the node_modules
directory and your package-lock.json
and re-run your test after a clean install?
If this doesn't help please provide the package.json
and karma.config
file.
Okay I will do this tomorrow and let you in ;)
Hello, I deleted node modules, package lock and rerun but the same issue :
11 12 2019 14:13:29.558:INFO [PhantomJS 2.1.1 (Windows 8.0.0)]: Connected on socket Si_EpP9Ey6zIsEutAAAA with id 78512712
ERROR: Please, report issue => Test file path not found! {} | xx| xxx: xx- xx
ERROR: Please, report issue => Test file path not found! {} | xx| xxx: xx- xx
Karma config :
module.exports = function (config) {
require("unit-testing-commons")(config, require("./webpack.config.js"));
config.set({
sonarqubeReporter: {
basePath: 'test', // test files folder
filePattern: '**/*spec.ts', // test files glob pattern
encoding: 'utf-8', // test files encoding
outputFolder: 'target', // report destination
legacyMode: true, // report for Sonarqube < 6.2 (disabled)
reportName: "karma-sonar-test.xml"
},
reporters: ['sonarqube'],
});
};
Package json :
"devDependencies": {
"awt-natif-pro-ent": "^1.x",
"babel-plugin-transform-class-properties": "=6.24.1",
"babel-plugin-transform-runtime": "=6.23.0",
"babel-preset-env": "=1.7.0",
"extend": "=3.0.0",
"karma": "=4.0.0",
"karma-phantomjs-launcher": "=1.0.2",
"karma-sonarqube-reporter": "=1.3.0",
"karma-webpack": "=3.0.5",
"webpack": "^4.x"
},
@helabenkhalfallah I couldn't reproduce this error with the information you provided. Is this all the content you have in your karma.conf.js
file? I don't see any test framework. Which ones are you using (jasmine, mocha, etc)? This is an example of a valid config file:
By the way, are you working with an Angular project?
Same here. Wasn't able to reproduce it... It would be really helpful if you could provide a create a Minimal, Reproducible Example.
@gearsdigital seem it fails if you use test data and string interpolation for test names in Jasmine.
Spec:
const expectedUrls = {
modern: 'test.com?fm=webp',
obsolete: 'test.com?fm=png&fl=png8',
};
const testData = [
{ browser: 'isChrome', url: 'test.com', expectedUrl: expectedUrls.modern },
{ browser: 'isIE', url: 'test.com', expectedUrl: expectedUrls.obsolete },
];
testData.forEach(({ browser, url, expectedUrl }) => {
it(`should return "${expectedUrl.split('?')[1]}" format for "${browser}"`, () => {
const browsers = {};
browsers[browser] = true;
fooService.getBrowsers.and.returnValue(browsers);
service = TestBed.get(BarService);
const actualUrl = service.getImageSrc({ url }, 'url');
expect(actualUrl).toBe(expectedUrl);
});
});
When running tests I get an error like:
ERROR: Please, report issue => Test file path not found! {JSON-Output} | BarService | should return "fm=webp" format for "IsChrome"
Parsed JSON shows:
"src/app/services/bar.service.spec.ts": {
"describe": [
"BarService",
],
"it": [
"should return \"${expectedUrl.split('?')[1]}\" format for \"${browser}\""
]
},
@AKharytonchyk This problem seems to be the same discussed on #18
Hello,
When I run test I got : ERROR: Please, report issue => Test file path not found! {} |
And the generated report is empty :
My Conf :
Thanks :)