index.test.js 1.12 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs-extra');
const globby = require('globby');
const path = require('path');
const {
  bootstrap,
  isSuccessfulDevelopment,
  isSuccessfulProduction,
} = require('../../utils');
beforeEach(async () => {
  await bootstrap({ directory: global.testDirectory, template: __dirname });
});

describe('relative paths', () => {
  // TODO: enable when development relative paths are supported
  xit('builds in development', async () => {
    await isSuccessfulDevelopment({ directory: global.testDirectory });
  });
  it('builds in production', async () => {
    await isSuccessfulProduction({ directory: global.testDirectory });

    const buildDir = path.join(global.testDirectory, 'build');
    const cssFile = path.join(
      buildDir,
      globby.sync('**/*.css', { cwd: buildDir }).pop()
    );
    const svgFile = path.join(
      buildDir,
      globby.sync('**/*.svg', { cwd: buildDir }).pop()
    );
    const desiredPath = /url\((.+?)\)/
      .exec(fs.readFileSync(cssFile, 'utf8'))
      .pop();
    expect(path.resolve(path.join(path.dirname(cssFile), desiredPath))).toBe(
      path.resolve(svgFile)
    );
  });
});