xdl
Version:
The Expo Development Library
149 lines (113 loc) • 5.33 kB
JavaScript
;
var _ProjectUtils;
function _load_ProjectUtils() {
return _ProjectUtils = _interopRequireWildcard(require('../../project/ProjectUtils'));
}
var _Config;
function _load_Config() {
return _Config = _interopRequireDefault(require('../../Config'));
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
jest.mock('analytics-node');
jest.mock('fs');
const mkdirp = require('mkdirp');
const mockfs = require('mock-fs');
const path = require('path');
const slugify = require('slugify');
const packageJson = {
name: 'testing123',
version: '0.5.0'
};
// these are intentionally different from package.json -- easy way to test fallbacks
const expJson = {
sdkVersion: '12.0.0',
name: 'My New Project',
slug: 'my-new-project',
version: '1.0.0'
};
const appJson = {
expo: {
sdkVersion: '12.0.0'
}
};
const packageJsonWithExp = {
name: 'testing456',
version: '0.7.0',
exp: expJson
};
const expJsonWithNodeModulesPath = {
sdkVersion: '12.0.0',
name: 'My New Project',
slug: 'my-new-project',
version: '1.0.0',
nodeModulesPath: 'node-modules-path'
};
function setupDirs() {
const fs = require('fs');
const packageJsonString = JSON.stringify(packageJson, null, 2);
fs.__configureFs({
'/home/mocky/appjson/package.json': packageJsonString,
'/home/mocky/appjson/app.json': JSON.stringify(appJson, null, 2),
'/home/mocky/expjson/package.json': packageJsonString,
'/home/mocky/expjson/exp.json': JSON.stringify(expJson, null, 2),
'/home/mocky/nojson/package.json': JSON.stringify(packageJsonWithExp, null, 2),
'/home/mocky/expjson-with-node-modules/exp.json': JSON.stringify(expJsonWithNodeModulesPath, null, 2),
'/home/mocky/expjson-with-node-modules/node-modules-path/package.json': packageJsonString
});
}
describe('configFilenameAsync', () => {
beforeEach(_asyncToGenerator(function* () {
setupDirs();
}));
afterEach(() => {
mockfs.restore();
});
it('checks configfile heuristics are correct', _asyncToGenerator(function* () {
const appJson = yield (_ProjectUtils || _load_ProjectUtils()).configFilenameAsync('/home/mocky/appjson');
expect(appJson).toEqual('app.json');
const expJson = yield (_ProjectUtils || _load_ProjectUtils()).configFilenameAsync('/home/mocky/expjson');
expect(expJson).toEqual('exp.json');
const prevDevTool = (_Config || _load_Config()).default.developerTool;
(_Config || _load_Config()).default.developerTool = 'exp';
const noExpJson = yield (_ProjectUtils || _load_ProjectUtils()).configFilenameAsync('/doesntexist');
expect(noExpJson).toEqual('exp.json');
(_Config || _load_Config()).default.developerTool = 'crna';
const noAppJson = yield (_ProjectUtils || _load_ProjectUtils()).configFilenameAsync('/doesntexist');
expect(noAppJson).toEqual('app.json');
(_Config || _load_Config()).default.developerTool = prevDevTool;
}));
});
describe('readConfigJsonAsync', () => {
beforeEach(_asyncToGenerator(function* () {
setupDirs();
}));
afterEach(() => {
mockfs.restore();
});
it('parses a project root with a normal exp.json', _asyncToGenerator(function* () {
const { exp, pkg } = yield (_ProjectUtils || _load_ProjectUtils()).readConfigJsonAsync('/home/mocky/expjson');
expect(exp).toEqual(expJson);
expect(pkg).toEqual(packageJson);
}));
it('parses a project root with only a package.json', _asyncToGenerator(function* () {
const { exp, pkg } = yield (_ProjectUtils || _load_ProjectUtils()).readConfigJsonAsync('/home/mocky/nojson');
expect(exp).toEqual(expJson);
expect(pkg).toEqual(packageJsonWithExp);
}));
it('parses a project root with an app.json relying on package.json fallbacks', _asyncToGenerator(function* () {
const { exp, pkg } = yield (_ProjectUtils || _load_ProjectUtils()).readConfigJsonAsync('/home/mocky/appjson');
expect(exp.sdkVersion).toEqual(appJson.expo.sdkVersion);
expect(exp.version).toEqual(packageJson.version);
expect(exp.name).toEqual(packageJson.name);
expect(exp.slug).toEqual(slugify(packageJson.name));
expect(pkg).toEqual(packageJson);
}));
it('reads package.json at nodeModulesPath', _asyncToGenerator(function* () {
const { exp, pkg } = yield (_ProjectUtils || _load_ProjectUtils()).readConfigJsonAsync('/home/mocky/expjson-with-node-modules');
expect(exp).toEqual(expJsonWithNodeModulesPath);
expect(pkg).toEqual(packageJson);
}));
});
//# sourceMappingURL=../../__sourcemaps__/__tests__/project/ProjectUtils-test.js.map