UNPKG

@johnf/react-native-owl

Version:
199 lines (198 loc) 7.38 kB
"use strict"; var _path = _interopRequireDefault(require("path")); var _execa = _interopRequireDefault(require("execa")); var _build = require("./build.js"); var _logger = require("../logger.js"); var configHelpers = _interopRequireWildcard(require("./config.js")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } describe('build.ts', () => { const logger = new _logger.Logger(); const execMock = jest.spyOn(_execa.default, 'command').mockImplementation(); beforeEach(() => { execMock.mockReset(); }); describe('buildIOS', () => { it('builds an iOS project with workspace/scheme', async () => { const config = { ios: { workspace: 'ios/RNDemo.xcworkspace', scheme: 'RNDemo', configuration: 'Debug', device: 'iPhone Simulator', env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildIOS)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`xcodebuild -workspace ios/RNDemo.xcworkspace -scheme RNDemo -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build`, { stdio: 'inherit', env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); it('builds an iOS project with scheme with a space in it', async () => { const config = { ios: { workspace: 'ios/RNDemo.xcworkspace', scheme: 'Demo With Space', configuration: 'Debug', device: 'iPhone Simulator', env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildIOS)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`xcodebuild -workspace ios/RNDemo.xcworkspace -scheme Demo\\ With\\ Space -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build`, { stdio: 'inherit', env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); it('builds an iOS project with workspace/scheme - with the quiet arg', async () => { const config = { ios: { workspace: 'ios/RNDemo.xcworkspace', scheme: 'RNDemo', configuration: 'Debug', quiet: true, device: 'iPhone Simulator', env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildIOS)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`xcodebuild -workspace ios/RNDemo.xcworkspace -scheme RNDemo -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build -quiet`, { stdio: 'inherit', env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); it('builds an iOS project with a custom build command', async () => { const config = { ios: { buildCommand: "echo 'Hello World'", device: 'iPhone Simulator', env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildIOS)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`echo 'Hello World'`, { stdio: 'inherit', env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); }); describe('buildAndroid', () => { it('builds an Android project with the default build command', async () => { const config = { android: { packageName: 'com.rndemo', env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildAndroid)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`./gradlew assembleRelease --console plain -PisOwlBuild=true`, { stdio: 'inherit', cwd: _path.default.join(process.cwd(), 'android'), env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); it('builds an Android project with the default build command - with the quiet arg', async () => { const config = { android: { packageName: 'com.rndemo', quiet: true, env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildAndroid)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`./gradlew assembleRelease --console plain --quiet -PisOwlBuild=true`, { stdio: 'inherit', cwd: _path.default.join(process.cwd(), 'android'), env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); it('builds an Android project with a custom build command', async () => { const config = { android: { packageName: 'com.rndemo', buildCommand: "echo 'Hello World'", env: { ENTRY_FILE: _build.ENTRY_FILE } } }; await (0, _build.buildAndroid)(config, logger); expect(execMock).toHaveBeenCalledTimes(1); expect(execMock).toHaveBeenCalledWith(`echo 'Hello World' -PisOwlBuild=true`, { stdio: 'inherit', env: { ENTRY_FILE: _build.ENTRY_FILE } }); }); }); describe('buildHandler', () => { const args = { platform: 'ios', config: './owl.config.json' }; const config = { ios: { buildCommand: "echo 'Hello World'", device: 'iPhone Simulator', env: { ENTRY_FILE: './node_modules/react-native-owl/dist/client/index.app.js' } }, android: { packageName: 'com.rndemo', buildCommand: "echo 'Hello World'", env: { ENTRY_FILE: './node_modules/react-native-owl/dist/client/index.app.js' } } }; jest.spyOn(_logger.Logger.prototype, 'print').mockImplementation(); it('builds an iOS project', async () => { jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config); const call = async () => (0, _build.buildHandler)(args); await expect(call()).resolves.not.toThrow(); }); it('builds an Android project', async () => { jest.spyOn(configHelpers, 'getConfig').mockResolvedValueOnce(config); const call = async () => (0, _build.buildHandler)({ ...args, platform: 'android' }); await expect(call()).resolves.not.toThrow(); }); }); }); //# sourceMappingURL=build.test.js.map