Files
react-native-community-cli/__e2e__/legacyInit.test.ts
Antón MolledaandMichał Pierzchała 5819a17d14 chore: make cleanup async (#1156)
* chore: make `cleanup` async

Using `rimraf.sync` can cause `ENOTEMPTY` and `EBUSY` errors on Windows.
This can make the Windows CI to fail randomly. Changing to the async
method defaults to autoretry 3 times and thus avoiding this issues.

* chore: jest config

* chore: e2e tests use sync cleanup

* chore: pr feedback

* chore: revert timeout

* Update __e2e__/default.test.ts

* Update __e2e__/default.test.ts

Co-authored-by: Michał Pierzchała <[email protected]>
2020-05-12 15:53:04 +02:00

81 lines
2.0 KiB
TypeScript

import fs from 'fs';
import path from 'path';
// @ts-ignore
import execa from 'execa';
import {getTempDirectory, cleanupSync, writeFiles} from '../jest/helpers';
const DIR = getTempDirectory('command-legacy-init');
beforeEach(() => {
cleanupSync(DIR);
writeFiles(DIR, {});
});
afterEach(() => {
cleanupSync(DIR);
});
// We skip this test, because it's flaky and we don't really update
// `react-native-cli` package anymore
test.skip('legacy init through react-native-cli', () => {
const templateFiles = [
'.buckconfig',
'.eslintrc.js',
'.flowconfig',
'.gitattributes',
'.gitignore',
'.prettierrc.js',
'.watchmanconfig',
'App.js',
'__tests__',
'android',
'app.json',
'babel.config.js',
'index.js',
'ios',
'metro.config.js',
'node_modules',
'package.json',
'yarn.lock',
];
const {stdout} = execa.sync('npx', ['react-native-cli', 'init', 'TestApp'], {
cwd: DIR,
});
expect(stdout).toContain('Run instructions');
// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toEqual(['TestApp']);
let dirFiles = fs.readdirSync(path.join(DIR, 'TestApp'));
expect(dirFiles.length).toEqual(templateFiles.length);
for (const templateFile of templateFiles) {
expect(dirFiles.includes(templateFile)).toBe(true);
}
const pkgJson = require(path.join(DIR, 'TestApp', 'package.json'));
expect(pkgJson).toMatchObject({
dependencies: {
react: expect.any(String),
'react-native': expect.any(String),
},
devDependencies: {
'@babel/core': expect.any(String),
'@babel/runtime': expect.any(String),
'babel-jest': expect.any(String),
jest: expect.any(String),
'metro-react-native-babel-preset': expect.any(String),
'react-test-renderer': expect.any(String),
},
jest: {
preset: 'react-native',
},
name: 'TestApp',
private: true,
scripts: {
start: 'react-native start',
test: 'jest',
},
});
});