public icon indicating copy to clipboard operation
public copied to clipboard

Can't find 'require' for Typescript files

Open tsawan opened this issue 10 years ago • 4 comments

Issue description or question

I have a very simple Typescript project. In my test spec, I tried to import the source file to test but it's giving Can't find 'require'. I've included the typescript compiler in my config. please check.

Wallaby.js configuration file

module.exports = function (wallaby) {
    return {
        "files": [
            "src/**/*.ts"
        ],

        "tests": [
            "test/**/*Spec.ts"
        ],
        "compilers": {
            "**/*.ts": wallaby.compilers.typeScript({})
        }
    }
};

Code editor or IDE name and version

WebStorm v11

OS name and version

OSX

tsawan avatar May 02 '16 04:05 tsawan

By default wallaby.js uses PhantomJs to run your tests. Your TypeScript files imports are compiled to CommonJs requires. Browser environment doesn't support CommonJs, hence the error.

If it is a node.js app that you are testing, then you need to specify the runner type, so your tests will run in node.

If it is a browser app that you are testing, then it depends on the technology your app itself is using. You may configure wallaby.js to use a module bundler, like Webpack or Browserify, or System.js.

Let me know if it addresses your issue.

ArtemGovorov avatar May 02 '16 04:05 ArtemGovorov

it's a browser app. and I'm using webpack. so how will it work with webpack/wallaby? I change the code, save the file, bundler will run and then the tests will run?

tsawan avatar May 02 '16 05:05 tsawan

Wallaby supports webpack as a postprocessor and it's fully integrated, so will work just as with other technologies that wallaby supports: no need to save the file, just write your code/tests, wallaby will take care of the rest. Have a look into the referenced docs section how to configure it, you may also clone and run this sample to quickly see how it works.

ArtemGovorov avatar May 02 '16 05:05 ArtemGovorov

that worked like a charm. Never expected it to be this easy. Many thanks.

tsawan avatar May 02 '16 05:05 tsawan