Edit this page
Learn how to extend EAS Build with custom build workflows.
Custom builds allow running tests on the cloud, adding instructions for native platforms, resigning a build to share with your team or multiple test devices, and so on. With EAS Build, you can create build configs to customize the process so that you're not limited to generating Android and iOS applications. You can also do anything that you might want to do in a CI environment.
This guide shows how to create and use a custom build config with EAS. It follows a scenario where you create a custom workflow to run tests on EAS Build. You can also use the defined steps in other scenarios.
1
To create a build config that runs tests, you have to prepare your project by installing jest-expo
and jest
as dependencies. Run the following command:
-
npx expo install -- --save-dev jest-expo jest react-test-renderer
Next, add a test
script in package.json:
{
"scripts": {
%%placeholder-start%%... %%placeholder-end%%
"test": "jest"
},
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
]
}
}
For brevity, let's create an App.test.js at the root of your project and then add the following snippet:
import renderer from 'react-test-renderer';
import App from './App';
describe('<App />', () => {
it('has 1 child', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree.children.length).toBe(1);
});
});
See Unit testing with Jest for more information about configuring the
jest-expo
package and additional configuration options such astransformIgnorePatterns
.
2
You must add a build config file in your project to create a workflow. Create a directory path .eas/build at the same level as eas.json. For example, if the eas.json file is at the root of your project, create the directory at that level. Both path and name of both directories are important for EAS Build to identify that a project contains a custom build config.
Inside it, you can create a new file called test.yml. This file contains the workflow config that you want to run. The filename is unimportant; you can name it whatever you want. The only requirement is that the file extension uses .yml.
This file will contain steps to run tests on the EAS Build service. It'll install all the required dependencies from the package.json file of your project and execute the npm test
script.
Add the following workflow steps in the file:
build:
name: Run tests
steps:
- eas/checkout
- run:
name: Install dependencies
command: npm install
- run:
name: Run tests
command: |
echo "Running tests..."
npm test
3
config
property in eas.jsonTo use the custom build config, you must add the config
property in eas.json. It contains the build config filename as the value you want to run on the EAS.
Let's create a new build profile called test
under build
to run the custom config from the test.yml file:
{
"build": {
%%placeholder-start%%... %%placeholder-end%%
"test": {
"config": "test.yml",
"withoutCredentials": true
},
}
Use the withoutCredentials
option to skip the credentials setup on the CLI side, as they are not needed for running tests.
If you wish to use separate configs for each platform, you can create separate YAML config files for Android and iOS. For example:
{
"build": {
%%placeholder-start%%... %%placeholder-end%%
"test": {
"ios": {
"config": "test-ios.yml",
},
"android": {
"config": "test-android.yml",
},
"withoutCredentials": true
},
}
4
To test the workflow, run the following command:
-
eas build -p android -e test
After the build is complete, you can verify that the npm test
script was executed by checking the logs on the build details page.
withoutCredentials
option as shown above. See App credentials docs for more information.Check out the example repository for more detailed examples:
A custom EAS Build example that includes examples for workflows such as setting up functions, using environment variables, uploading artifacts, and more.