Skip to content

Commit

Permalink
chore(metro-runtime): improve url support testing (#25240)
Browse files Browse the repository at this point in the history
# Why

Tests were technically failing, this fixes them. Related
#25171
  • Loading branch information
EvanBacon committed Nov 6, 2023
1 parent 224da15 commit f0e222b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/@expo/metro-runtime/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### 💡 Others

- Improve testing for URL support on native. ([#25240](https://github.com/expo/expo/pull/25240) by [@EvanBacon](https://github.com/EvanBacon))
- Migrate to new standard `URL` support on native. ([#24941](https://github.com/expo/expo/pull/24941) by [@EvanBacon](https://github.com/EvanBacon))

## 3.0.3 — 2023-10-17
Expand Down
25 changes: 25 additions & 0 deletions packages/@expo/metro-runtime/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {
getWebPreset,
// getNodePreset,
getIOSPreset,
getAndroidPreset,
} = require('jest-expo/config/getPlatformPreset');
const { withWatchPlugins } = require('jest-expo/config/withWatchPlugins');

function withDefaults({ watchPlugins, ...config }) {
return {
...config,
clearMocks: true,
roots: ['src'],
};
}

module.exports = withWatchPlugins({
projects: [
// Create a new project for each platform.
getWebPreset(),
// getNodePreset(),
getIOSPreset(),
getAndroidPreset(),
].map(withDefaults),
});
16 changes: 0 additions & 16 deletions packages/@expo/metro-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,5 @@
},
"peerDependencies": {
"react-native": "*"
},
"jest": {
"projects": [
{
"preset": "jest-expo/ios",
"clearMocks": true
},
{
"preset": "jest-expo/android",
"clearMocks": true
},
{
"preset": "jest-expo/web",
"clearMocks": true
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,41 @@ jest.mock('../../getDevServer', () => ({
default: jest.fn(),
}));

it(`returns an expected URL`, () => {
const originalEnv = process.env;

beforeEach(() => {
process.env = { ...originalEnv };
delete window.location;
});

afterAll(() => {
process.env = originalEnv;
delete window.location;
});

it(`returns an expected URL in production`, () => {
process.env.NODE_ENV = 'production';

// Mock the location object
window.location = {
origin: 'http://localhost:19000',
};

expect(buildUrlForBundle('/foobar')).toEqual('http://localhost:19000/foobar');
});

it(`asserts in production that the origin was not specified at build-time`, () => {
process.env.NODE_ENV = 'production';

// Don't mock the location object...

expect(() => buildUrlForBundle('/foobar')).toThrow(
/Unable to determine the production URL where additional JavaScript chunks are hosted because the global "location" variable is not defined\./
);
});
it(`returns an expected URL in development`, () => {
process.env.NODE_ENV = 'development';

asMock(getDevServer).mockReturnValueOnce({
bundleLoadedFromServer: true,
fullBundleUrl:
Expand Down

0 comments on commit f0e222b

Please sign in to comment.