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
29 changes: 0 additions & 29 deletions __e2e__/__snapshots__/init.test.ts.snap

This file was deleted.

100 changes: 37 additions & 63 deletions __e2e__/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ import {run, getTempDirectory, cleanup, writeFiles} from '../jest/helpers';

const DIR = getTempDirectory('command-init');

function createCustomTemplateFiles() {
writeFiles(DIR, {
'custom/template/template.config.js': `module.exports = {
placeholderName: 'HelloWorld',
templateDir: './template-dir',
};`,
'custom/template/package.json':
'{ "name": "template", "version": "0.0.1" }',
'custom/template/template-dir/package.json': '{}',
'custom/template/template-dir/file': '',
'custom/template/template-dir/dir/file': '',
});
}

const customTemplateCopiedFiles = [
'dir',
'file',
'node_modules',
'package.json',
'yarn.lock',
];

beforeEach(() => {
cleanup(DIR);
writeFiles(DIR, {});
Expand All @@ -21,64 +43,34 @@ test('init --template fails without package name', () => {
expect(stderr).toContain('missing required argument');
});

const templateFiles = [
'.buckconfig',
'.eslintrc.js',
'.flowconfig',
'.gitattributes',
// should be here, but it's not published yet
// '.gitignore',
'.watchmanconfig',
'App.js',
'__tests__',
'android',
'babel.config.js',
'index.js',
'ios',
'metro.config.js',
'node_modules',
'package.json',
'yarn.lock',
];
test('init --template filepath', () => {
createCustomTemplateFiles();
let templatePath = path.resolve(DIR, 'custom', 'template');
if (process.platform === 'win32') {
templatePath = templatePath.split('\\').join('/');
}

test('init --template', () => {
const {stdout} = run(DIR, [
'init',
'--template',
'react-native-new-template',
`file://${templatePath}`,
'TestInit',
]);

expect(stdout).toContain('Welcome to React Native!');
expect(stdout).toContain('Run instructions');

// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toEqual(['TestInit']);
expect(fs.readdirSync(DIR)).toContain('custom');

let dirFiles = fs.readdirSync(path.join(DIR, 'TestInit'));
expect(dirFiles.length).toEqual(templateFiles.length);

for (const templateFile of templateFiles) {
expect(dirFiles.includes(templateFile)).toBe(true);
}

const pkgJson = require(path.join(DIR, 'TestInit', 'package.json'));
expect(pkgJson).toMatchSnapshot(
'package.json contains necessary configuration',
);
expect(dirFiles).toEqual(customTemplateCopiedFiles);
});

test('init --template file:/tmp/custom/template', () => {
writeFiles(DIR, {
'custom/template/template.config.js': `module.exports = {
placeholderName: 'HelloWorld',
templateDir: './template-dir',
};`,
'custom/template/package.json':
'{ "name": "template", "version": "0.0.1" }',
'custom/template/template-dir/package.json': '{}',
'custom/template/template-dir/empty': '',
});
test('init --template file with custom directory', () => {
createCustomTemplateFiles();
const projectName = 'TestInit';
const customPath = 'custom-path';
let templatePath = path.resolve(DIR, 'custom', 'template');
if (process.platform === 'win32') {
templatePath = templatePath.split('\\').join('/');
Expand All @@ -88,20 +80,6 @@ test('init --template file:/tmp/custom/template', () => {
'init',
'--template',
`file://${templatePath}`,
'TestInit',
]);

expect(stdout).toContain('Run instructions');
});

test('init --template with custom project path', () => {
const projectName = 'TestInit';
const customPath = 'custom-path';

const {stdout} = run(DIR, [
'init',
'--template',
'react-native-new-template',
projectName,
'--directory',
'custom-path',
Expand All @@ -111,12 +89,8 @@ test('init --template with custom project path', () => {
expect(stdout).toContain(customPath);

// make sure we don't leave garbage
expect(fs.readdirSync(DIR)).toEqual([customPath]);
expect(fs.readdirSync(DIR)).toContain(customPath);

let dirFiles = fs.readdirSync(path.join(DIR, customPath));
expect(dirFiles.length).toEqual(templateFiles.length);

for (const templateFile of templateFiles) {
expect(dirFiles.includes(templateFile)).toBe(true);
}
expect(dirFiles).toEqual(customTemplateCopiedFiles);
});
4 changes: 3 additions & 1 deletion __e2e__/legacyInit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ afterEach(() => {
cleanup(DIR);
});

test('legacy init through react-native-cli', () => {
// 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',
Expand Down