Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: Please, report issue => Test file path not found! {} | #23

Open
helabenkhalfallah opened this issue Oct 28, 2019 · 23 comments · Fixed by #24
Open

ERROR: Please, report issue => Test file path not found! {} | #23

helabenkhalfallah opened this issue Oct 28, 2019 · 23 comments · Fixed by #24

Comments

@helabenkhalfallah
Copy link

Hello,

When I run test I got :
ERROR: Please, report issue => Test file path not found! {} |

And the generated report is empty :

<?xml version='1.0'?>
<testExecutions version='1'/>

My Conf :

config.set({
        // Default configuration
        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'
        ],
    });
 "karma": "=0.13.22",
  "karma-sonarqube-reporter": "^1.2.5",

Thanks :)

@fadc80
Copy link
Owner

fadc80 commented Nov 10, 2019

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!

@helabenkhalfallah
Copy link
Author

I will try using a more recent version of karma, thank you :) :)

@fadc80
Copy link
Owner

fadc80 commented Nov 11, 2019

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.

@helabenkhalfallah
Copy link
Author

Hello @fadc80 I changed karma version to "karma": "=4.0.0", but I have the same issue. :(

@fadc80
Copy link
Owner

fadc80 commented Nov 13, 2019

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.

@gearsdigital
Copy link
Contributor

gearsdigital commented Nov 24, 2019

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

Walk through

  1. onSpecComplete defined in index.js checks if a test is successful, skipped or failed
  2. In case of describe.skip(), this.specSkipped is invoked and calls
  3. pathfinder.testFile, which iterates over all matched files and invokes
  4. exist() for each file but returns undefined because
  5. existDescribe looks for a property describe on an object which was never created

Explanation

The 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;
}

Long story short

I fixed this issue in #24 by slightly changing the regular expression. It now matches:

  1. describe.skip
  2. describe.only
  3. fdescribe
  4. xdescribe
  5. it.skip
  6. it.only
  7. fit
  8. xit

All of this is afaik valid at least for Mocha and Jasmine

Adapted regular expression

((\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.

@helabenkhalfallah
Copy link
Author

Hello @gearsdigital , your fix seems good for me, I will try to modify on my local and let you in ;) Thanks. :)

@gearsdigital
Copy link
Contributor

gearsdigital commented Nov 24, 2019

@helabenkhalfallah I wonder if you can confirm to have skipped tests on your setup.

@fadc80
Copy link
Owner

fadc80 commented Nov 25, 2019

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.

@gearsdigital
Copy link
Contributor

@fadc80 Do you need a sample project to verify? I can provide mine if you want...

@fadc80
Copy link
Owner

fadc80 commented Nov 26, 2019

It would be good! 👍

@gearsdigital
Copy link
Contributor

There you go: https://github.com/gearsdigital/karma-sonarqube-reporter-issue-23

@fadc80
Copy link
Owner

fadc80 commented Nov 30, 2019

@all-contributors please add @helabenkhalfallah as a contributor for bug.

@allcontributors
Copy link
Contributor

@fadc80

I've put up a pull request to add @helabenkhalfallah! 🎉

@helabenkhalfallah
Copy link
Author

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 :)

@helabenkhalfallah
Copy link
Author

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);
    });

});

@fadc80 fadc80 reopened this Dec 2, 2019
@gearsdigital
Copy link
Contributor

gearsdigital commented Dec 2, 2019

@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.

@helabenkhalfallah
Copy link
Author

Okay I will do this tomorrow and let you in ;)

@helabenkhalfallah
Copy link
Author

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"
  },

@fadc80
Copy link
Owner

fadc80 commented Dec 12, 2019

@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:

// Example of a typical configuration
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular/cli'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-firefox-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-sonarqube-reporter'),
require('@angular/cli/plugins/karma')
],
client:{
clearContext: false
},
coverageIstanbulReporter: {
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
sonarqubeReporter: {
basePath: 'src/app',
outputFolder: 'reports',
filePattern: '**/*spec.ts',
encoding: 'utf-8',
legacyMode: false,
reportName: (metadata) => {
return metadata.concat('xml').join('.');
}
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml', 'sonarqube'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome', 'Firefox'],
singleRun: false
});
};

By the way, are you working with an Angular project?

@gearsdigital
Copy link
Contributor

Same here. Wasn't able to reproduce it... It would be really helpful if you could provide a create a Minimal, Reproducible Example.

@AKharytonchyk
Copy link

@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}\""
        ]
    },

@fadc80
Copy link
Owner

fadc80 commented Jun 27, 2020

@AKharytonchyk This problem seems to be the same discussed on #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants