Skip to content

Commit

Permalink
Allow disabling Blob Cxx module (#11979)
Browse files Browse the repository at this point in the history
* Define FetchTest

* Implement fetch test

* Allow disabling Blob Cxx module

* Change files

* Format FetchTest.js

* yarn lint
  • Loading branch information
JunielKatarn authored Aug 4, 2023
1 parent 89e16c7 commit bde337f
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": "prerelease",
"comment": "Allow disabling Blob Cxx module",
"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 @@ -223,5 +223,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 @@ -554,17 +554,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 @@ -156,6 +156,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 bde337f

Please sign in to comment.