wallabyjs / public

Repository for Wallaby.js questions and issues
http://wallabyjs.com
759 stars 45 forks source link

Test-files starting with a dot #701

Closed andr2 closed 8 years ago

andr2 commented 8 years ago

Issue description or question

Test-file is invisible for wallaby if the file starts with a dot (.tests.ts for example)

Wallaby.js configuration file

module.exports = (wallaby) => {
    var path = require('path');
    process.env.NODE_PATH = path.resolve(process.cwd() + "/../build/node_modules");

    return {
        files: [
            { pattern: '../build/node_modules/mithril/mithril.js', instrument: false },
            { pattern: 'lib/mithril.js', instrument: false },
            { pattern: '../build/node_modules/chance/chance.js', instrument: false },
            '**/*.ts',
            "!**/*.tests.ts", "!**/.tests.ts",
        ],
        tests: [
            "**/*.tests.ts", "**/.tests.ts"
        ],
        compilers: {
            '**/*.ts': wallaby.compilers.typeScript({ module: 'commonjs', moduleResolution: 'node' })
        },
        env: {
            type: 'node'
        },
        testFramework: 'mocha',
        setup: function () {
            global.assert = require('chai').assert;
            global.m = require('mithril');
        }
    }
}

VSCode insiders build Windows 10

ArtemGovorov commented 8 years ago

Wallaby.js is using the default glob matching settings and the .tests.ts file name doesn't match the **/*.ts pattern:

> require('minimatch')('.tests.ts', '**/*.ts')
false

You may do this:

var tsCompiler = wallaby.compilers.typeScript({ module: 'commonjs', moduleResolution: 'node' });
...
compilers: {
            '**/*.ts': tsCompiler,
            '**/.*.ts': tsCompiler
        },

Let me know if it addresses the issue for you.

andr2 commented 8 years ago

In config-file I have "**/.tests.ts", and minimatch returns true for this:

> require('minimatch')('path/.tests.js', '**/.tests.js')
true

But wallaby ignores the file

andr2 commented 8 years ago

Ah, I understand that the problem is in compilers section. But this config also doesn't work:

module.exports = (wallaby) => {
    var path = require('path');
    process.env.NODE_PATH = path.resolve(process.cwd() + "/../build/node_modules");

    var tsCompiler = wallaby.compilers.typeScript({ module: 'commonjs', moduleResolution: 'node' });
    return {
        files: [
            { pattern: '../build/node_modules/mithril/mithril.js', instrument: false },
            { pattern: 'lib/mithril.js', instrument: false },
            { pattern: '../build/node_modules/chance/chance.js', instrument: false },
            '**/*.ts',
            "!**/*.tests.ts", "!**/.tests.ts",
        ],
        tests: [
            "**/*.tests.ts", "**/.tests.ts"
        ],
        compilers: {
            '**/*.ts': tsCompiler,
            '**/.tests.ts': tsCompiler
        },
        env: {
            type: 'node'
        },
        testFramework: 'mocha',
        setup: function () {
            global.assert = require('chai').assert;
            global.m = require('mithril');
        }
    }
}

Wallaby simply ignores form/.tests.ts

ArtemGovorov commented 8 years ago

Thanks for providing more details. There was indeed a bug in the watcher, it's now fixed in the core v1.0.265. It should update automatically within a few minutes during wallaby restarts, here is how to force the upgrade to happen immediately.

andr2 commented 8 years ago

Thanks a lot, now it works correctly!

ArtemGovorov commented 8 years ago

Awesome, thanks for the update!

faceyspacey commented 7 years ago

@ArtemGovorov this pattern doesn't work either:

{ pattern: '.storybook/**/*.js', load: false },

ArtemGovorov commented 7 years ago

@faceyspacey Just tried the pattern and it's working for me: screen shot 2017-02-26 at 12 55 42 pm

Any hints how to reproduce the issue? Perhaps you could share a sample repo?

faceyspacey commented 7 years ago
git clone git@github.com:faceyspacey/animated-transition-group.git
yarn
npm test // to see that jest testing works properly

In, the file stories/index.js you will see that it fails to import a mocked file from the .storybook folder on line 7:

wallabyshot

If you cd into the projects/id/instrumented directory you will see that the .storybook folder does not get added, even though its supplied in the wallaby files config.

ArtemGovorov commented 7 years ago

Cloned the repo, but I can see the folder and of the files in it being copied:

screen shot 2017-02-26 at 1 35 36 pm
faceyspacey commented 7 years ago

that's very weird. for me, it's not being copied.

ArtemGovorov commented 7 years ago

What's your OS and node.js version?

faceyspacey commented 7 years ago

damn my bad. i forgot to run ls -a i.e. with the -a param. ..it's being copied, but the test isn't working within wallaby. is it working for you?

faceyspacey commented 7 years ago

OSX 10.11.6 NODE v7.0.0

ArtemGovorov commented 7 years ago

@faceyspacey Nope, the test isn't working, but it's definitely not because of the missing files, because the files are there. Will have a look into it.

faceyspacey commented 7 years ago

To see if it had to do with jest's mocking functionality, i've tried not mocking it as well and it still can't get that facade.js file. It seems it's struggling to dig into a hidden directory.

ArtemGovorov commented 7 years ago

@faceyspacey Looking into the instrumented/.storybook/__mocks__/facade.js - the file is instrumented, but it looks like ES6 imports are not compiled to CommonJs for some reason.

faceyspacey commented 7 years ago

same with the instrumented/.storybook/facade.js ....it must have to do with storybook's way of operating, rather than that hidden folder.

ArtemGovorov commented 7 years ago

I think I found the reason. It may sound unintuitive, but for example the file .storybook/facade.js doesn't match this glob pattern: **/*.js. You may check it yourself:

node require('minimatch')('.storybook/facade.js', '*/.js') false

So the compiler doesn't compile those files in the .storybook folder. Here's the solution:

const compiler = wallaby.compilers.babel({ babelrc: true, presets: ['babel-preset-jest'] });
...
    compilers: {
      '**/*.js': compiler,
      '.**/**/*.js': compiler
    },
...

After you do this, you'll see another (not related) issue. You'll need to exclude .snap files from your tests list and include them into the files list, as specified in the docs.

faceyspacey commented 7 years ago

excellent, it works! thanks brother. ...it's not requiring me to exclude .snap files from my tests list, but if it ever does, i know what to do. thanks again.