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

electron require directory #827

Closed
tamascsaba opened this issue Oct 13, 2016 · 2 comments
Closed

electron require directory #827

tamascsaba opened this issue Oct 13, 2016 · 2 comments

Comments

@tamascsaba
Copy link

tamascsaba commented Oct 13, 2016

I want to use electron nodeIntegration to require tests and test require your files, which speed up lot of my test running process (with wallaby-webpack or wallabify runs very slow).

Wallaby.js configuration file

module.exports = function (wallaby) {
  return {
    debug: true,
    files: [
      {pattern: 'src/client/testing/setup.ts'},
      {pattern: 'src/client/**/*.ts', load: false},
      {pattern: 'src/client/**/*.test.ts', ignore: true}
    ],

    tests: [
      {pattern: 'src/client/**/*.test.ts', load: false},
    ],

    testFramework: 'jasmine',

    env: {
      kind: 'electron',
      runner: require('electron'),
      options: {
        webPreferences: {
          nodeIntegration: true
        }
      }
    },

    bootstrap: function (w) {
      require('module').globalPaths.push(require('path').join(process.cwd(), 'node_modules'));
      requireGlob([w.baseDir + '/**/*test.js']).then(function (modules) {
        console.log(modules); // load nothing 
      });
    }
  };
};

Example test

foo.test.ts

import {foo} from './foo';

describe('foo', () => {
  it('to be defined', () => {
    expect(foo).toEqual({foo: true});
  });
});

Code editor or IDE name and version

WebStorm 2016.02.3

OS name and version

Linux

@ArtemGovorov
Copy link
Member

ArtemGovorov commented Oct 13, 2016

The bootstrap (AKA setup) function is sync, so that's why the then callaback is not called. You may try using delayStart and then start:

bootstrap: function (w) {
      w.delayStart();
      require('module').globalPaths.push(require('path').join(process.cwd(), 'node_modules'));
      requireGlob([w.baseDir + '/**/*test.js']).then(function (modules) {
        ...
        w.start();
      });
    }

but I haven't tried this specific setup (Electron+node require for tests/files). When our user want better performance they normally just switch their tests to use plain node with wallaby plus jsdom if DOM interaction is required.

@tamascsaba
Copy link
Author

Thanks, for quick answer, unfortunately it does not work :( requireGlob load my modules but webstorm not show anything.

I can't use node until angular/zone.js#475 will be merged, but nice idea

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