Skip to content

Commit

Permalink
chore: disable editTemplate test on Node v20 (#2235)
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrybczak authored Dec 22, 2023
1 parent acdcb2b commit c0c0cfa
Showing 1 changed file with 89 additions and 69 deletions.
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

0 comments on commit c0c0cfa

Please sign in to comment.