1import {
2  replaceEnvironmentVariables,
3  getTransformEnvironment,
4} from '../environmentVariableSerializerPlugin';
5
6describe(getTransformEnvironment, () => {
7  [
8    '/index.bundle?platform=web&dev=true&transform.environment=node&hot=false',
9    '/index.bundle?transform.environment=node&platform=web&dev=true&hot=false',
10    '/index.bundle?platform=web&dev=true&hot=false&transform.environment=node',
11    '/index.bundle?transform.environment=node',
12  ].forEach((url) => {
13    it(`extracts environment from ${url}`, () => {
14      expect(getTransformEnvironment(url)).toBe('node');
15    });
16  });
17  it(`works with missing transform`, () => {
18    expect(
19      getTransformEnvironment(
20        '/index.bundle?transform.environment=&platform=web&dev=true&hot=false'
21      )
22    ).toBe(null);
23    expect(getTransformEnvironment('/index.bundle?&platform=web&dev=true&hot=false')).toBe(null);
24  });
25});
26
27describe(replaceEnvironmentVariables, () => {
28  it('matches environment variables', () => {
29    const contents = replaceEnvironmentVariables(
30      `
31                const foo = process.env.JEST_WORKER_ID;
32                process.env.ABC;
33                console.log(process.env.NODE_ENV);
34                console.log(process.env.EXPO_PUBLIC_NODE_ENV);
35                process.env.EXPO_PUBLIC_FOO;
36
37                a + b = c;
38
39                env.EXPO_PUBLIC_URL;
40
41                process.env['other'];
42                `,
43      { EXPO_PUBLIC_NODE_ENV: 'development', EXPO_PUBLIC_FOO: 'bar' }
44    );
45    expect(contents).toMatch('development');
46    expect(contents).toMatch('bar');
47    expect(contents).toMatch('process.env.NODE_ENV');
48    expect(contents).toMatch('process.env.JEST_WORKER_ID');
49    expect(contents).not.toMatch('EXPO_PUBLIC_NODE_ENV');
50    expect(contents).not.toMatch('EXPO_PUBLIC_FOO');
51    expect(contents).toMatchSnapshot();
52  });
53});
54