env.test.js 2.67 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
import initDOM from './initDOM';
9
10
11

describe('Integration', () => {
  describe('Environment variables', () => {
12
    it('file env variables', async () => {
13
      const doc = await initDOM('file-env-variables');
14

15
      expect(
16
        doc.getElementById('feature-file-env-original-1').textContent
17
      ).toBe('from-original-env-1');
18
19
      expect(
        doc.getElementById('feature-file-env-original-2').textContent
20
      ).toBe('override-from-original-local-env-2');
21
22

      if (process.env.NODE_ENV === 'production') {
23
        expect(doc.getElementById('feature-file-env').textContent).toBe(
24
25
          'production'
        );
26
        expect(doc.getElementById('feature-file-env-x').textContent).toBe(
27
28
29
          'x-from-production-env'
        );
      } else {
30
        expect(doc.getElementById('feature-file-env').textContent).toBe(
31
32
          'development'
        );
33
        expect(doc.getElementById('feature-file-env-x').textContent).toBe(
34
35
36
          'x-from-development-env'
        );
      }
37
      doc.defaultView.close();
38
    });
39

40
    it('NODE_PATH', async () => {
41
      const doc = await initDOM('node-path');
42

43
      expect(doc.getElementById('feature-node-path').childElementCount).toBe(4);
44
      doc.defaultView.close();
45
    });
46

47
    it('PUBLIC_URL', async () => {
48
49
      const doc = await initDOM('public-url');

50
51
52
53
      const prefix =
        process.env.NODE_ENV === 'development'
          ? ''
          : 'http://www.example.org/spa';
54
      expect(doc.getElementById('feature-public-url').textContent).toBe(
55
56
57
58
        `${prefix}.`
      );
      expect(
        doc.querySelector('head link[rel="shortcut icon"]').getAttribute('href')
59
      ).toBe(`${prefix}/favicon.ico`);
60
      doc.defaultView.close();
61
    });
62

63
    it('shell env variables', async () => {
64
65
66
67
      const doc = await initDOM('shell-env-variables');

      expect(
        doc.getElementById('feature-shell-env-variables').textContent
68
      ).toBe('fromtheshell.');
69
      doc.defaultView.close();
70
    });
71
72
73
74

    it('expand .env variables', async () => {
      const doc = await initDOM('expand-env-variables');

75
      expect(doc.getElementById('feature-expand-env-1').textContent).toBe(
76
77
        'basic'
      );
78
      expect(doc.getElementById('feature-expand-env-2').textContent).toBe(
79
80
        'basic'
      );
81
      expect(doc.getElementById('feature-expand-env-3').textContent).toBe(
82
83
84
85
        'basic'
      );
      expect(
        doc.getElementById('feature-expand-env-existing').textContent
86
      ).toBe('fromtheshell');
87
      doc.defaultView.close();
88
    });
89
90
  });
});