|
1 | 1 | import fs from 'fs'; |
2 | 2 | import path from 'path'; |
| 3 | +import execa from 'execa'; |
3 | 4 | import {runCLI, getTempDirectory, cleanup, writeFiles} from '../jest/helpers'; |
4 | 5 | import slash from 'slash'; |
5 | 6 |
|
@@ -43,6 +44,15 @@ if (process.platform === 'win32') { |
43 | 44 | templatePath = `file://${templatePath}`; |
44 | 45 | } |
45 | 46 |
|
| 47 | +function isYarnAvailable() { |
| 48 | + try { |
| 49 | + execa.sync('yarn', ['--version'], {stdio: 'pipe'}); |
| 50 | + return true; |
| 51 | + } catch (error) { |
| 52 | + return false; |
| 53 | + } |
| 54 | +} |
| 55 | + |
46 | 56 | test('init fails if the directory already exists and --replace-directory false', () => { |
47 | 57 | fs.mkdirSync(path.join(DIR, PROJECT_NAME)); |
48 | 58 |
|
@@ -152,6 +162,34 @@ test('init skips installation of dependencies with --skip-install', () => { |
152 | 162 | ); |
153 | 163 | }); |
154 | 164 |
|
| 165 | +test('init supports --pm yarn together with --skip-install', () => { |
| 166 | + if (!isYarnAvailable()) { |
| 167 | + return; |
| 168 | + } |
| 169 | + |
| 170 | + createCustomTemplateFiles(); |
| 171 | + |
| 172 | + const {stdout, stderr} = runCLI(DIR, [ |
| 173 | + 'init', |
| 174 | + '--template', |
| 175 | + templatePath, |
| 176 | + PROJECT_NAME, |
| 177 | + '--pm', |
| 178 | + 'yarn', |
| 179 | + '--skip-install', |
| 180 | + ]); |
| 181 | + |
| 182 | + expect(stderr).not.toContain(`Couldn't find the "`); |
| 183 | + expect(stdout).toContain('Run instructions'); |
| 184 | + |
| 185 | + const dirFiles = fs.readdirSync(path.join(DIR, PROJECT_NAME)).sort(); |
| 186 | + const expectedFiles = customTemplateCopiedFiles |
| 187 | + .filter((file) => !['node_modules', 'package-lock.json'].includes(file)) |
| 188 | + .concat(['.yarn', '.yarnrc.yml']) |
| 189 | + .sort(); |
| 190 | + expect(dirFiles).toEqual(expectedFiles); |
| 191 | +}); |
| 192 | + |
155 | 193 | // react-native-macos stopped shipping `template.config.js` for 0.75, so this test is disabled. in future releases we should re-enable once `template.config.js` will be there again. |
156 | 194 | test.skip('init --platform-name should work for out of tree platform', () => { |
157 | 195 | createCustomTemplateFiles(); |
|
0 commit comments