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

ant-design-pro-template运行npm run test报错 #776

Closed
lys623 opened this issue Jan 20, 2018 · 15 comments
Closed

ant-design-pro-template运行npm run test报错 #776

lys623 opened this issue Jan 20, 2018 · 15 comments

Comments

@lys623
Copy link

lys623 commented Jan 20, 2018

image

@chenshuai2144
Copy link
Collaborator

应该是少了一个运行库

@jwmann
Copy link

jwmann commented Jan 22, 2018

I have the same problem.

Steps to reproduce.

$> npm i -g ant-design-pro-cli
$> pro new
$> cd demo
$> npm test

image

@jwmann
Copy link

jwmann commented Jan 22, 2018

Jest also fails

image

@jwmann
Copy link

jwmann commented Jan 22, 2018

I thought perhaps the issue might have something to do with roadhog@2.2.0 but the error happens for roadhog@2.1.0 as well. 😭

@jwmann
Copy link

jwmann commented Jan 22, 2018

Further testing shows that it's failing at this node module path

/node_modules/umi-test/lib/transformers/jsTransformer.js

roadhog is looking for umi-test@^0.3.0 however a fresh install will install umi-test@^0.3.1
If you manually install npm i umi-test@0.3.0 you get different error messages. The same errors that Jest above is giving.

@jwmann
Copy link

jwmann commented Jan 22, 2018

Was #640 merged without testing? Every module warning seems to related to the removed modules in this commit

@jwmann
Copy link

jwmann commented Jan 22, 2018

umi-test 0.3.1 is broken

So umi-test@^0.3.1 changes the way it exports its module in its jsTransformer.js
By doing that, jest-runtime is looking for a process function which because umi-test isn't exported properly, it will fail.

jest-runtime sees this transform object:

{ 
  default: { 
    canInstrument: true,
    getCacheKey: [Function: getCacheKey],
    process: [Function: process] 
  } 
}

But jest-runtime's script_transformer.js is checking for transform.process not transform.default.process
Fixing either the above or umi-test will make it work but it will still result in the errors of missing modules.

umi-test@0.3.1 breaks
Fix by doing npm i umi-test@0.3.0

With umi-test temporarily fixed. Missing modules!

Now for missing module errors.

 FAIL  src/routes/Result/Success.test.js
  Test suite failed to run

    Cannot find module 'babel-plugin-transform-runtime' from '/Users/jwmann/work//'
    - Did you mean "@babel/transform-runtime"?

    ...

I did a npm i babel-plugin-transform-runtime and then a npm i babel-preset-2015 as per the next missing module error.

Finally ending up with:

Plugin/Preset files are not allowed to export objects, only functions.

Now I'm officially stuck. 😭

@chenshuai2144
Copy link
Collaborator

I can not reproduce it 。。。。。

@jwmann
Copy link

jwmann commented Jan 23, 2018

What version is your /node_modules/umi-test?
At the very least that shouldn't be working, the author of the module has confirmed the bug.

@jwmann
Copy link

jwmann commented Jan 24, 2018

Now that umi-test has reverted 0.3.1 to 0.3.0

I decided to start fresh.
The tests don't have the same error, some of them seem to pass although with warnings.

Still fails from fresh install.
image

@chenshuai2144
Copy link
Collaborator

关注中

@jwmann
Copy link

jwmann commented Jan 24, 2018

Yes very. I can't use this software unless these tests are working at the very least from the demo

@jwmann
Copy link

jwmann commented Jan 24, 2018

Alright, so I think the issue if that my computer is too slow to actually run these tests in a reasonable timeframe.

Also we aren't passing the done() function into the it() tests.
Source: https://stackoverflow.com/a/25273095/185731

These are my modified tests:

login.e2e.js

import Nightmare from 'nightmare';

describe('Login', () => {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; // 5 minute timeout
  let page;
  beforeEach(() => {
    page = Nightmare();
    page
      .goto('http://localhost:8000/')
      .evaluate(() => {
        window.localStorage.setItem('antd-pro-authority', 'guest');
      })
      .goto('http://localhost:8000/#/user/login');
  });

  it('should login with failure', async (done) => {
    await page.type('#userName', 'mockuser')
      .type('#password', 'wrong_password')
      .click('button[type="submit"]')
      .wait('.ant-alert-error') // should display error
      .end();
    done();
  });

  it('should login successfully', async (done) => {
    const text = await page.type('#userName', 'admin')
      .type('#password', '888888')
      .click('button[type="submit"]')
      .wait('.ant-layout-sider h1') // should display error
      .evaluate(() => document.body.innerHTML)
      .end();
    expect(text).toContain('<h1>Ant Design Pro</h1>');
    done();
  });
});

home.e2e.js

import Nightmare from 'nightmare';

describe('Homepage', () => {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 300000; // 5 minute timeout
  it('it should have logo text', async (done) => {
    const page = Nightmare().goto('http://localhost:8000');
    const text = await page.wait('h1').evaluate(() => document.body.innerHTML).end();
    expect(text).toContain('<h1>Ant Design Pro</h1>');
    done();
  });
});

@jwmann
Copy link

jwmann commented Jan 24, 2018

image

@chenshuai2144
Copy link
Collaborator

fix in #1006

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.

3 participants