• Jack Zhao's avatar
    Convert test suite to Jest (#4550) · d0ed8450
    Jack Zhao authored
    * convert mocha tests to jest
    
    * jest 23
    
    * add jest configs
    
    * use material css
    
    * fix windows
    
    * forceExit jest test
    
    * force exit eject
    
    * test
    
    * test
    
    * retrigger test
    
    * remove appveyor comment
    
    * try to remove pretendToBeVisual option
    
    * use jsdom env
    
    * test environment
    
    * no cache
    
    * test no close
    
    * bring back raf
    
    * test revert all broken changes
    
    * add back jsdom
    
    * remove jsdom
    
    * node test environment
    
    * use latest change
    
    * runInBand
    
    * runInBand
    
    * comment test run
    
    * try different jest option
    
    * standardize jest test options
    
    * increase heap size
    
    * remove heap size config
    
    * support scoped packages for cra --scripts-version option
    
    * upgrade jest version
    
    * fix windows
    
    * fix windows again
    
    * jest 23.4.1
    
    * babel-jest
    
    * babel-jest
    
    * split out kitchhensink
    
    * travis node 6
    
    * travis node 6 config
    
    * node 6 travis eject
    
    * cache yarn
    
    * only cache yarn
    
    * remove unrelate...
    d0ed8450
webpack.test.js 5.38 KiB
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
import initDOM, { resourceLoader } from './initDOM';
import url from 'url';
const matchCSS = (doc, regexes) => {
  if (process.env.E2E_FILE) {
    const elements = doc.getElementsByTagName('link');
    let href = '';
    for (const elem of elements) {
      if (elem.rel === 'stylesheet') {
        href = elem.href;
    resourceLoader({ url: url.parse(href) }, (_, textContent) => {
      for (const regex of regexes) {
        expect(textContent).toMatch(regex);
    });
  } else {
    for (let i = 0; i < regexes.length; ++i) {
      expect(
        doc.getElementsByTagName('style')[i].textContent.replace(/\s/g, '')
      ).toMatch(regexes[i]);
describe('Integration', () => {
  describe('Webpack plugins', () => {
    it('css inclusion', async () => {
      const doc = await initDOM('css-inclusion');
      matchCSS(doc, [
        /html\{/,
        /#feature-css-inclusion\{background:.+;color:.+}/,
      ]);
      doc.defaultView.close();
    });
    it('css modules inclusion', async () => {
      const doc = await initDOM('css-modules-inclusion');
      matchCSS(doc, [
        /.+style_cssModulesInclusion__.+\{background:.+;color:.+}/,
        /.+assets_cssModulesIndexInclusion__.+\{background:.+;color:.+}/,
      ]);
      doc.defaultView.close();
    });
    it('scss inclusion', async () => {
      const doc = await initDOM('scss-inclusion');
      matchCSS(doc, [/#feature-scss-inclusion\{background:.+;color:.+}/]);
      doc.defaultView.close();
    });
    it('scss modules inclusion', async () => {
      const doc = await initDOM('scss-modules-inclusion');
      matchCSS(doc, [
        /.+scss-styles_scssModulesInclusion.+\{background:.+;color:.+}/,
        /.+assets_scssModulesIndexInclusion.+\{background:.+;color:.+}/,
      ]);
      doc.defaultView.close();
    });
    it('sass inclusion', async () => {
      const doc = await initDOM('sass-inclusion');
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
matchCSS(doc, [/#feature-sass-inclusion\{background:.+;color:.+}/]); doc.defaultView.close(); }); it('sass modules inclusion', async () => { const doc = await initDOM('sass-modules-inclusion'); matchCSS(doc, [ /.+sass-styles_sassModulesInclusion.+\{background:.+;color:.+}/, /.+assets_sassModulesIndexInclusion.+\{background:.+;color:.+}/, ]); doc.defaultView.close(); }); it('graphql files inclusion', async () => { const doc = await initDOM('graphql-inclusion'); const children = doc.getElementById('graphql-inclusion').children; // .graphql expect(children[0].textContent.replace(/\s/g, '')).toBe( '{"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"test"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"test"},"value":{"kind":"StringValue","value":"test","block":false}}],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"test"},"arguments":[],"directives":[]}]}}]}}],"loc":{"start":0,"end":40,"source":{"body":"{\\ntest(test:\\"test\\"){\\ntest\\n}\\n}\\n","name":"GraphQLrequest","locationOffset":{"line":1,"column":1}}}}' ); doc.defaultView.close(); }); it('image inclusion', async () => { const doc = await initDOM('image-inclusion'); expect(doc.getElementById('feature-image-inclusion').src).toMatch( /^data:image\/jpeg;base64.+==$/ ); doc.defaultView.close(); }); it('no ext inclusion', async () => { const doc = await initDOM('no-ext-inclusion'); expect(doc.getElementById('feature-no-ext-inclusion').href).toMatch( /\/static\/media\/aFileWithoutExt\.[a-f0-9]{8}\.bin$/ ); doc.defaultView.close(); }); it('json inclusion', async () => { const doc = await initDOM('json-inclusion'); expect(doc.getElementById('feature-json-inclusion').textContent).toBe( 'This is an abstract.' ); doc.defaultView.close(); }); it('linked modules', async () => { const doc = await initDOM('linked-modules'); expect(doc.getElementById('feature-linked-modules').textContent).toBe( '2.0.0' ); doc.defaultView.close(); }); it('svg inclusion', async () => { const doc = await initDOM('svg-inclusion'); expect(doc.getElementById('feature-svg-inclusion').src).toMatch( /\/static\/media\/logo\..+\.svg$/ ); doc.defaultView.close(); }); it('svg component', async () => { const doc = await initDOM('svg-component');
141142143144145146147148149150151152153154155156157158159160161162
expect(doc.getElementById('feature-svg-component').textContent).toBe(''); doc.defaultView.close(); }); it('svg in css', async () => { const doc = await initDOM('svg-in-css'); matchCSS(doc, [/\/static\/media\/logo\..+\.svg/]); doc.defaultView.close(); }); it('unknown ext inclusion', async () => { const doc = await initDOM('unknown-ext-inclusion'); expect(doc.getElementById('feature-unknown-ext-inclusion').href).toMatch( /\/static\/media\/aFileWithExt\.[a-f0-9]{8}\.unknown$/ ); doc.defaultView.close(); }); }); });