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

Test files in different folder, not stored at common location #20

Open
vkadam opened this issue Mar 18, 2014 · 2 comments
Open

Test files in different folder, not stored at common location #20

vkadam opened this issue Mar 18, 2014 · 2 comments

Comments

@vkadam
Copy link

vkadam commented Mar 18, 2014

In our project we are not storing test files under one location, those are stored related to each source file. So each module will have its test folder. Also we are using mongoose client. So all our mongoose related model files gets loaded (required) in server.js/index.js. What this means that in test case we do not load model file like

var myModel = require('myModule')

but we load it like

var mongoose = require('mongoose');
var myModel = mongoose.model('ModelName');

So we can't use requireHandler for loading model as its getting loaded in server.js/index.js

So we needed a way to keep using require instead of requireHandler but still load instrumented file instead of source one, so we updated our require_handler.js to

if (process.env.APP_DIR_FOR_CODE_COVERAGE) {
    var extname = '.js',
        ext_super = require.extensions[extname],
        filePatternMatch = /\/app\/(?!.*\/test\/)(?!.*_spec\.).*\.(js$)/;
    require.extensions[extname] = function ext(module, filename) {
        filename = filename.match(filePatternMatch) ? filename.replace('/app/', process.env.APP_DIR_FOR_CODE_COVERAGE) : filename;
        return ext_super(module, filename);
    };
}

Basically hook while loading module using require

@vkadam
Copy link
Author

vkadam commented Mar 18, 2014

I would be nice it this can be part of plugin it self. Load instrumented files from instrumented folder while running coverage.

@gregjopa
Copy link
Contributor

gregjopa commented Jun 3, 2014

I answered this question in: gregjopa/express-app-testing-demo#1. I think this issue can be closed.

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

No branches or pull requests

2 participants