Skip to content

Add Windows support #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2020
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
52 changes: 52 additions & 0 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Windows CI
on: [watch]

jobs:
run-windows-tests:
name: Build & run tests
runs-on: windows-2019

steps:
- uses: actions/checkout@v2
name: Checkout Code

- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: '12.9.1'

- name: Setup MSBuild
uses: microsoft/[email protected]
with:
vs-version: 16.5

- name: Check node modules cache
uses: actions/cache@v1
id: yarn-cache
with:
path: ./Example/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Install node modules
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
cd Example
yarn --pure-lockfile

- name: Build x64 release
run: |
cd Example
npx react-native run-windows --release --no-packager --no-launch --logging

- name: Start Appium server
shell: powershell
run: |
cd Example
Start-Process PowerShell -ArgumentList "yarn appium"

- name: Run tests
run: |
cd Example
yarn test:windows
3 changes: 3 additions & 0 deletions Example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ buck-out/

# CocoaPods
/ios/Pods/

# MSBuild Binary and Structured Log
*.binlog
14 changes: 14 additions & 0 deletions Example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ To read from another file just specify it with `ENVFILE`, like:
$ ENVFILE=.env.prod react-native run-android
```

## Running on Windows

To use the default `.env` file:

```console
npx react-native run-windows
```

To read from another file:
```console
set ENVFILE=.env.production
npx react-native run-windows
```

## Running from Xcode

Open the Xcode project file in `Example/ios/Example.xcodeproj`.
Expand Down
23 changes: 23 additions & 0 deletions Example/__tests__/ShowEnv.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { driver, By2 } from 'selenium-appium'
import { until } from 'selenium-webdriver';

const setup = require('../jest-setups/jest.setup');
jest.setTimeout(60000);

beforeAll(() => {
return driver.startWithCapabilities(setup.capabilites);
});

afterAll(() => {
return driver.quit();
});

describe('Test App', () => {

test('API_URL present', async () => {
// Get the element by label, will fail if the element is not present
// we use the API_URL from the .env file
await driver.wait(until.elementLocated(By2.nativeName('API_URL=http://localhost')));
});

})
12 changes: 12 additions & 0 deletions Example/jest-setups/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { windowsAppDriverCapabilities } from 'selenium-appium'

switch (platform) {
case "windows":
const webViewWindowsAppId = 'ReactNativeConfigWinExample_nsp2ha5jnb6xr!App';
module.exports = {
capabilites: windowsAppDriverCapabilities(webViewWindowsAppId)
}
break;
default:
throw "Unknown platform: " + platform;
}
1 change: 1 addition & 0 deletions Example/jest-setups/jest.setup.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
platform = "windows"
16 changes: 16 additions & 0 deletions Example/metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@
*
* @format
*/
const path = require('path');
const blacklist = require('metro-config/src/defaults/blacklist');

module.exports = {
resolver: {
blacklistRE: blacklist([
// This stops "react-native run-windows" from causing the metro server to crash if its already running
new RegExp(
`${path.resolve(__dirname, 'windows').replace(/[/\\]/g, '/')}.*`,
),
// This prevents "react-native run-windows" from hitting: EBUSY: resource busy or locked, open msbuild.ProjectImports.zip
new RegExp(
`${path
.resolve(__dirname, 'msbuild.ProjectImports.zip')
.replace(/[/\\]/g, '/')}.*`,
),
]),
},
transformer: {
getTransformOptions: async () => ({
transform: {
Expand Down
11 changes: 9 additions & 2 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@
"private": true,
"scripts": {
"android": "react-native run-android",
"appium": "appium",
"ios": "react-native run-ios",
"windows": "react-native run-windows",
"start": "react-native start",
"test": "jest",
"test:windows": "yarn jest --setupFiles=./jest-setups/jest.setup.windows.js",
"lint": "eslint .",
"postinstall": "node ../scripts/examples_postinstall.js"
},
"dependencies": {
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-config": "../"
"react-native-config": "../",
"react-native-windows": "^0.62.0-0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^0.0.5",
"appium": "^1.18.1",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.58.0",
"react-test-renderer": "16.11.0"
"react-test-renderer": "16.11.0",
"selenium-appium": "^0.0.15",
"selenium-webdriver": "^4.0.0-alpha.7"
},
"jest": {
"preset": "react-native"
Expand Down
92 changes: 92 additions & 0 deletions Example/windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
*AppPackages*
*BundleArtifacts*

#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.opendb
*.unsuccessfulbuild
ipch/
[Oo]bj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb

#MonoDevelop
*.pidb
*.userprefs

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*
*.sass-cache

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

# vim Temp Files
*~

#NuGet
packages/
*.nupkg

#ncrunch
*ncrunch*
*crunch*.local.xml

# visual studio database projects
*.dbmdl

#Test files
*.testsettings

#Other files
*.DotSettings
.vs/
*project.lock.json

#Files generated by the VS build
**/Generated Files/**

Loading