Skip to content
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

chore: disable editTemplate test on Node v20 #2235

Merged
merged 1 commit into from
Dec 22, 2023
Merged
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
158 changes: 89 additions & 69 deletions packages/cli/src/commands/init/__tests__/editTemplate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {
validatePackageName,
replaceNameInUTF8File,
} from '../editTemplate';
import semver from 'semver';

const skipIfNode20 = semver.major(process.version) === 20 ? test.skip : test;

const FIXTURE_DIR = path.resolve(
__dirname,
Expand Down Expand Up @@ -44,7 +47,7 @@ afterEach(() => {
fs.removeSync(testPath);
});

test('should edit template', async () => {
skipIfNode20('should edit template', async () => {
jest.spyOn(process, 'cwd').mockImplementation(() => testPath);

await changePlaceholderInTemplate({
Expand Down Expand Up @@ -96,7 +99,7 @@ test('should edit template', async () => {
).toMatchSnapshot();
});

test('should edit template with custom title', async () => {
skipIfNode20('should edit template with custom title', async () => {
jest.spyOn(process, 'cwd').mockImplementation(() => testPath);

await changePlaceholderInTemplate({
Expand Down Expand Up @@ -140,25 +143,28 @@ describe('changePlaceholderInTemplate', () => {
jest.resetAllMocks();
});

test(`should produce a lowercased version of "${PROJECT_NAME}" in package.json "name" field`, async () => {
await changePlaceholderInTemplate({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
});

const oldPackageJsonFile = fs.readFileSync(
path.resolve(FIXTURE_DIR, 'package.json'),
'utf8',
);
const newPackageJsonFile = fs.readFileSync(
path.resolve(testPath, 'package.json'),
'utf8',
);

expect(
snapshotDiff(oldPackageJsonFile, newPackageJsonFile, {contextLines: 1}),
).toMatchSnapshot();
});
skipIfNode20(
`should produce a lowercased version of "${PROJECT_NAME}" in package.json "name" field`,
async () => {
await changePlaceholderInTemplate({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
});

const oldPackageJsonFile = fs.readFileSync(
path.resolve(FIXTURE_DIR, 'package.json'),
'utf8',
);
const newPackageJsonFile = fs.readFileSync(
path.resolve(testPath, 'package.json'),
'utf8',
);

expect(
snapshotDiff(oldPackageJsonFile, newPackageJsonFile, {contextLines: 1}),
).toMatchSnapshot();
},
);
});

describe('replacePlaceholderWithPackageName', () => {
Expand All @@ -170,22 +176,25 @@ describe('replacePlaceholderWithPackageName', () => {
jest.resetAllMocks();
});

test(`should replace name in package.json with ${PACKAGE_NAME} value`, async () => {
await replacePlaceholderWithPackageName({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
placeholderTitle: 'Test',
packageName: PACKAGE_NAME,
});
const packageJsonFile = fs.readFileSync(
path.resolve(testPath, 'package.json'),
'utf8',
);

expect(JSON.parse(packageJsonFile).name).toBe(PACKAGE_NAME);
});
skipIfNode20(
`should replace name in package.json with ${PACKAGE_NAME} value`,
async () => {
await replacePlaceholderWithPackageName({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
placeholderTitle: 'Test',
packageName: PACKAGE_NAME,
});
const packageJsonFile = fs.readFileSync(
path.resolve(testPath, 'package.json'),
'utf8',
);

expect(JSON.parse(packageJsonFile).name).toBe(PACKAGE_NAME);
},
);

test('should update the bundle ID for iOS', async () => {
skipIfNode20('should update the bundle ID for iOS', async () => {
await replacePlaceholderWithPackageName({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
Expand All @@ -204,45 +213,56 @@ describe('replacePlaceholderWithPackageName', () => {
).toBeTruthy();
});

test(`should rename Main component name for Android with ${PROJECT_NAME}`, async () => {
await replacePlaceholderWithPackageName({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
placeholderTitle: 'Test',
packageName: PACKAGE_NAME,
});

const mainActivityFile = fs.readFileSync(
path.resolve(
testPath,
'android',
'com',
PACKAGE_NAME,
'MainActivity.java',
),
'utf8',
);

expect(mainActivityFile.includes(`return "${PROJECT_NAME}"`)).toBeTruthy();
});
skipIfNode20(
`should rename Main component name for Android with ${PROJECT_NAME}`,
async () => {
await replacePlaceholderWithPackageName({
projectName: PROJECT_NAME,
placeholderName: PLACEHOLDER_NAME,
placeholderTitle: 'Test',
packageName: PACKAGE_NAME,
});

const mainActivityFile = fs.readFileSync(
path.resolve(
testPath,
'android',
'com',
PACKAGE_NAME,
'MainActivity.java',
),
'utf8',
);

expect(
mainActivityFile.includes(`return "${PROJECT_NAME}"`),
).toBeTruthy();
},
);
});

describe('validatePackageName', () => {
test('should throw an error when package name contains only one segment', () => {
expect(() => validatePackageName('example')).toThrowError(
'The package name example is invalid. It should contain at least two segments, e.g. com.app',
);
});
skipIfNode20(
'should throw an error when package name contains only one segment',
() => {
expect(() => validatePackageName('example')).toThrowError(
'The package name example is invalid. It should contain at least two segments, e.g. com.app',
);
},
);

test('should throw an error when package name contains special characters other than dots', () => {
expect(() => validatePackageName('com.organization.a@pp')).toThrowError(
'The com.organization.a@pp package name is not valid. It can contain only alphanumeric characters and dots.',
);
});
skipIfNode20(
'should throw an error when package name contains special characters other than dots',
() => {
expect(() => validatePackageName('com.organization.a@pp')).toThrowError(
'The com.organization.a@pp package name is not valid. It can contain only alphanumeric characters and dots.',
);
},
);
});

describe('replaceNameInUTF8File', () => {
test('should replace string in utf8 file', async () => {
skipIfNode20('should replace string in utf8 file', async () => {
const pathToUtf8File = path.join(
testPath,
'ios',
Expand All @@ -266,7 +286,7 @@ describe('replaceNameInUTF8File', () => {
expect(afterReplacement).toContain(textToReplace);
});

test('should not replace string in utf8 file', async () => {
skipIfNode20('should not replace string in utf8 file', async () => {
const fsWriteFileSpy = jest.spyOn(fs, 'writeFile');
const pathToUtf8File = path.join(
testPath,
Expand Down