webpack.test.js 3.71 KB
Newer Older
1
2
3
/**
 * Copyright (c) 2015-present, Facebook, Inc.
 *
Sophie Alpert's avatar
Sophie Alpert committed
4
5
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
6
7
 */

8
9
import { expect } from 'chai';
import initDOM from './initDOM';
10
11
12
13

describe('Integration', () => {
  describe('Webpack plugins', () => {
    it('css inclusion', async () => {
14
      const doc = await initDOM('css-inclusion');
15

16
17
      expect(
        doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
18
19
20
      ).to.match(/html\{/);
      expect(
        doc.getElementsByTagName('style')[1].textContent.replace(/\s/g, '')
21
22
      ).to.match(/#feature-css-inclusion\{background:.+;color:.+}/);
    });
23

24
25
26
27
28
29
30
31
32
33
    it('css modules inclusion', async () => {
      const doc = await initDOM('css-modules-inclusion');

      expect(
        doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
      ).to.match(
        /.+__style-module___cssModulesInclusion+\{background:.+;color:.+}/
      );
    });

34
35
36
37
38
39
40
41
42
43
    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, '')).to.equal(
        '{"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}}}}'
      );
    });

44
    it('image inclusion', async () => {
45
      const doc = await initDOM('image-inclusion');
46

47
48
49
50
      expect(doc.getElementById('feature-image-inclusion').src).to.match(
        /^data:image\/jpeg;base64.+==$/
      );
    });
51
52

    it('no ext inclusion', async () => {
53
      const doc = await initDOM('no-ext-inclusion');
54

55
56
57
58
      expect(doc.getElementById('feature-no-ext-inclusion').href).to.match(
        /\/static\/media\/aFileWithoutExt\.[a-f0-9]{8}\.bin$/
      );
    });
59
60

    it('json inclusion', async () => {
61
      const doc = await initDOM('json-inclusion');
62

63
64
65
66
      expect(doc.getElementById('feature-json-inclusion').textContent).to.equal(
        'This is an abstract.'
      );
    });
67

Joe Haddad's avatar
Joe Haddad committed
68
69
70
71
72
73
74
75
    it('linked modules', async () => {
      const doc = await initDOM('linked-modules');

      expect(doc.getElementById('feature-linked-modules').textContent).to.equal(
        '2.0.0'
      );
    });

76
    it('svg inclusion', async () => {
77
      const doc = await initDOM('svg-inclusion');
78

79
80
81
82
      expect(doc.getElementById('feature-svg-inclusion').src).to.match(
        /\/static\/media\/logo\..+\.svg$/
      );
    });
83

84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    it('svg component', async () => {
      const doc = await initDOM('svg-component');

      expect(doc.getElementById('feature-svg-component').textContent).to.equal(
        ''
      );
    });

    it('svg in css', async () => {
      const doc = await initDOM('svg-in-css');

      expect(
        doc.getElementsByTagName('style')[0].textContent.replace(/\s/g, '')
      ).to.match(/\/static\/media\/logo\..+\.svg/);
    });

100
    it('unknown ext inclusion', async () => {
101
102
103
104
105
106
107
108
      const doc = await initDOM('unknown-ext-inclusion');

      expect(doc.getElementById('feature-unknown-ext-inclusion').href).to.match(
        /\/static\/media\/aFileWithExt\.[a-f0-9]{8}\.unknown$/
      );
    });
  });
});