env.test.js 2.62 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

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

16
      expect(
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        doc.getElementById('feature-file-env-original-1').textContent
      ).to.equal('from-original-env-1');
      expect(
        doc.getElementById('feature-file-env-original-2').textContent
      ).to.equal('override-from-original-local-env-2');

      if (process.env.NODE_ENV === 'production') {
        expect(doc.getElementById('feature-file-env').textContent).to.equal(
          'production'
        );
        expect(doc.getElementById('feature-file-env-x').textContent).to.equal(
          'x-from-production-env'
        );
      } else {
        expect(doc.getElementById('feature-file-env').textContent).to.equal(
          'development'
        );
        expect(doc.getElementById('feature-file-env-x').textContent).to.equal(
          'x-from-development-env'
        );
      }
38
    });
39

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

43
44
45
46
      expect(
        doc.getElementById('feature-node-path').childElementCount
      ).to.equal(4);
    });
47

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

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

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

      expect(
        doc.getElementById('feature-shell-env-variables').textContent
      ).to.equal('fromtheshell.');
    });
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

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

      expect(doc.getElementById('feature-expand-env-1').textContent).to.equal(
        'basic'
      );
      expect(doc.getElementById('feature-expand-env-2').textContent).to.equal(
        'basic'
      );
      expect(doc.getElementById('feature-expand-env-3').textContent).to.equal(
        'basic'
      );
      expect(
        doc.getElementById('feature-expand-env-existing').textContent
      ).to.equal('fromtheshell');
    });
87
88
  });
});