Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .ado/templates/react-native-init-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ steps:
parameters:
buildLogDirectory: '$(Build.BinariesDirectory)\${{ parameters.platform }}\${{ parameters.configuration }}\BuildLogs'

# Only run the following on apps
- ${{ if endsWith(parameters.template, '-app') }}:
- script: call yarn test:windows
displayName: Run jest tests with react-test-renderer
workingDirectory: $(Agent.BuildDirectory)\testcli

# Only test bundling in debug since we already bundle as part of release builds
- ${{ if and(endsWith(parameters.template, '-app'), eq(parameters.configuration, 'Debug')) }}:
- script: npx react-native bundle --entry-file index.js --platform windows --bundle-output test.bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fabric: Enable react-test-renderer tests in the new cpp-app template",
"packageName": "react-native-windows",
"email": "jthysell@microsoft.com",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions vnext/templates/cpp-app/jest.config.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = {};

module.exports = require('@rnx-kit/jest-preset')('windows', config);
13 changes: 11 additions & 2 deletions vnext/templates/cpp-app/template.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,20 @@ async function getFileMappings(config = {}, options = {}) {
}

async function postInstall(config = {}, options = {}) {
// Update package.json with new scripts
// Update package.json with new scripts and dependencies
await templateUtils.updateProjectPackageJson(config, options, {
scripts: {windows: 'react-native run-windows'},
scripts: {
windows: 'react-native run-windows',
'test:windows': 'jest --config jest.config.windows.js',
},
devDependencies: {
'@rnx-kit/jest-preset': '^0.1.16',
},
});

// Install recently added dependencies
await templateUtils.runNpmInstall(config, options);

console.log(chalk.white.bold('To run your new windows app:'));
console.log(chalk.white(' npx react-native run-windows'));
}
Expand Down
20 changes: 19 additions & 1 deletion vnext/templates/templateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@
* @format
*/

const existsSync = require('fs').existsSync;
const path = require('path');
const util = require('util');
const exec = util.promisify(require('child_process').exec);

const pkgUtils = require('@react-native-windows/package-utils');

async function runNpmInstall(config = {}, options = {}) {
const projectPath = config?.root ?? process.cwd();

if (options?.logging) {
console.log('Installing dependencies...');
}
const isYarn = existsSync(path.join(projectPath, 'yarn.lock'));
await exec(
isYarn ? 'yarn' : 'npm i',
options?.logging ? {stdio: 'inherit'} : {},
);
}

async function updateProjectPackageJson(config = {}, options = {}, props = {}) {
const projectPath = config?.root ?? process.cwd();
const projectPackage = await pkgUtils.WritableNpmPackage.fromPath(
Expand All @@ -26,4 +44,4 @@ async function updateProjectPackageJson(config = {}, options = {}, props = {}) {
await projectPackage.mergeProps(props);
}

module.exports = {updateProjectPackageJson};
module.exports = {runNpmInstall, updateProjectPackageJson};