Skip to content

Commit

Permalink
[0.71] Allow disabling Blob Cxx module (#11984)
Browse files Browse the repository at this point in the history
* Allow disabling Blob Cxx module (#11979)

* Define FetchTest

* Implement fetch test

* Allow disabling Blob Cxx module

* Change files

* Format FetchTest.js

* yarn lint

* Remove change files

* Change files
  • Loading branch information
JunielKatarn committed Aug 4, 2023
1 parent 958bd7b commit d543e65
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Allow disabling Blob Cxx module (#11979)",
"packageName": "react-native-windows",
"email": "julio.rocha@microsoft.com",
"dependentChangeType": "patch"
}
7 changes: 7 additions & 0 deletions vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,12 @@ TEST_CLASS (RNTesterIntegrationTests) {
Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str());
}

BEGIN_TEST_METHOD_ATTRIBUTE(Fetch)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(Fetch) {
auto result = m_runner.RunTest("IntegrationTests/FetchTest", "FetchTest");
Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str());
}

#pragma endregion Extended Tests
};
23 changes: 13 additions & 10 deletions vnext/Shared/OInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,20 @@ std::vector<std::unique_ptr<NativeModule>> InstanceImpl::GetDefaultNativeModules
},
nativeQueue));

modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetBlobModuleName(),
[transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
nativeQueue));
// Use in case the host app provides its a non-Blob-compatilbe HTTP module.
if (!Microsoft::React::GetRuntimeOptionBool("Blob.DisableModule")) {
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetBlobModuleName(),
[transitionalProps]() { return Microsoft::React::CreateBlobModule(transitionalProps); },
nativeQueue));

modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetFileReaderModuleName(),
[transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
nativeQueue));
modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Microsoft::React::GetFileReaderModuleName(),
[transitionalProps]() { return Microsoft::React::CreateFileReaderModule(transitionalProps); },
nativeQueue));
}

modules.push_back(std::make_unique<CxxNativeModule>(
m_innerInstance,
Expand Down
4 changes: 4 additions & 0 deletions vnext/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
"type": "platform",
"file": "src/IntegrationTests/DummyTest.js"
},
{
"type": "platform",
"file": "src/IntegrationTests/FetchTest.js"
},
{
"type": "platform",
"file": "src/IntegrationTests/LoggingTest.js"
Expand Down
53 changes: 53 additions & 0 deletions vnext/src/IntegrationTests/FetchTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
* @format
* @flow
*/

'use strict';

const React = require('react');
const ReactNative = require('react-native');

const {AppRegistry, View} = ReactNative;

const {TestModule} = ReactNative.NativeModules;

const uri =
'https://raw.githubusercontent.com/microsoft/react-native-windows/main/.yarnrc.yml';
const expectedContent = 'enableScripts: false';

type State = {
uri: string,
expected: string,
content: string,
};

class FetchTest extends React.Component<{...}, State> {
state: State = {
uri: 'https://raw.githubusercontent.com/microsoft/react-native-windows/main/.yarnrc.yml',
expected: 'enableScripts: false',
content: '',
};

async componentDidMount() {
const response = await fetch(uri);
const text = await response.text();
this.setState({content: text});

if (this.state.content === expectedContent) {
TestModule.markTestPassed(true);
} else {
TestModule.markTestPassed(false);
}
}

render(): React.Node {
return <View />;
}
}

AppRegistry.registerComponent('FetchTest', () => FetchTest);

module.exports = FetchTest;

0 comments on commit d543e65

Please sign in to comment.