1 | import path from 'path';
|
2 | import fs from 'fs';
|
3 | import assert from 'assert';
|
4 | import {transformFileSync} from 'babel-core';
|
5 | import plugin from '../src/index';
|
6 |
|
7 | function trim(str) {
|
8 | return str.replace(/^\s+|\s+$/, '');
|
9 | }
|
10 |
|
11 | describe('The replace-object-assign plugin', () => {
|
12 | const fixturesDir = path.join(__dirname, 'fixtures');
|
13 | fs.readdirSync(fixturesDir).map((caseName) => {
|
14 | it(`should ${caseName.split('-').join(' ')}`, () => {
|
15 | const fixtureDir = path.join(fixturesDir, caseName);
|
16 | const pluginConfig = [plugin];
|
17 | if (caseName !== 'use-default-config') {
|
18 | pluginConfig.push({ moduleSpecifier: 'simple-assign' });
|
19 | }
|
20 | const actual = transformFileSync(path.join(fixtureDir, 'actual.js'), {
|
21 | plugins: [
|
22 | pluginConfig
|
23 | ]
|
24 | }).code;
|
25 | const expected = fs.readFileSync(path.join(fixtureDir, 'expected.js')).toString();
|
26 |
|
27 | assert.equal(trim(actual), trim(expected));
|
28 | });
|
29 | });
|
30 | });
|