Skip to content

Commit

Permalink
metro bundler using mock API file if configured to
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Jan 3, 2023
1 parent f19d936 commit 0dc1d85
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 21 deletions.
17 changes: 17 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,32 @@

const {getDefaultConfig} = require('metro-config');
const _ = require('underscore');
require('dotenv').config();

/* eslint arrow-body-style: 0 */
module.exports = (() => {
const isUsingMockAPI = process.env.USE_MOCK_API === 'true' || process.env.E2E_TESTING === 'true';
if (isUsingMockAPI) {
// eslint-disable-next-line no-console
console.warn('⚠️ Using mock API');
}

return getDefaultConfig()
.then((config) => {
return {
resolver: {
assetExts: _.filter(config.resolver.assetExts, ext => ext !== 'svg'),
sourceExts: ['jsx', 'js', 'ts', 'tsx', 'json', 'svg'],
resolveRequest: (context, moduleName, platform) => {
const resolution = context.resolveRequest(context, moduleName, platform);
if (isUsingMockAPI && moduleName.includes('/API')) {
return {
...resolution,
filePath: resolution.filePath.replace(/src\/libs\/API.js/, 'src/libs/E2E/API.mock.js'),
};
}
return resolution;
},
},
transformer: {
getTransformOptions: () => ({
Expand Down
35 changes: 27 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"babel-polyfill": "^6.26.0",
"dom-serializer": "^0.2.2",
"domhandler": "^4.3.0",
"dotenv": "^8.2.0",
"expensify-common": "git+https://github.com/Expensify/expensify-common.git#e67235baa887dcbe9dc4bf41ddf1925f19a1e8ad",
"fbjs": "^3.0.2",
"file-loader": "^6.0.0",
Expand Down Expand Up @@ -162,6 +161,7 @@
"copy-webpack-plugin": "^6.4.1",
"css-loader": "^5.2.4",
"diff-so-fancy": "^1.3.0",
"dotenv": "^16.0.3",
"electron": "^21.2.2",
"electron-builder": "23.5.0",
"electron-notarize": "^1.2.1",
Expand Down
8 changes: 4 additions & 4 deletions src/libs/API/API.js → src/libs/API.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _ from 'underscore';
import Onyx from 'react-native-onyx';
import * as Request from '../Request';
import * as SequentialQueue from '../Network/SequentialQueue';
import pkg from '../../../package.json';
import CONST from '../../CONST';
import * as Request from './Request';
import * as SequentialQueue from './Network/SequentialQueue';
import pkg from '../../package.json';
import CONST from '../CONST';

/**
* All calls to API.write() will be persisted to disk as JSON with the params, successData, and failureData.
Expand Down
8 changes: 0 additions & 8 deletions src/libs/API/index.js

This file was deleted.

File renamed without changes.

0 comments on commit 0dc1d85

Please sign in to comment.