Skip to content

Commit

Permalink
tests: Update string test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
angelmadames committed Mar 2, 2024
1 parent 18f6c34 commit 07a8529
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 38 deletions.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@jest/globals": "^29.7.0",
"@types/bun": "latest"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/compose.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, afterAll, describe, expect, test } from 'bun:test';
import { afterAll, beforeEach, describe, expect, test } from 'bun:test';
import { projectConfig } from '../../src/config/project';
import { composeExecParams, composeFiles } from '../../src/utils/compose';
import { testSetup, testTeardown } from '../lifecycle';
Expand Down
1 change: 0 additions & 1 deletion test/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { setupCommand } from '../src/commands/setup';
import cliConfig from '../src/config/cli';
import { projectConfig } from '../src/config/project';
import { deletePath } from '../src/utils/file-system';
import { omitConsoleLogs } from './helpers';

const PROJECT = 'test';

Expand Down
16 changes: 8 additions & 8 deletions test/utils/file-system.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ import {
describe('Utils: file-system', () => {
test('isFile returns true if file exists', () => {
const exists = isFile('./cli.ts');
expect(exists).toBeTrue();
expect(exists).toBe(true);
});

test("isFile returns false if file doesn't exist", () => {
const exists = isFile('./cli.not.exists.ts');
expect(exists).toBeFalse();
expect(exists).toBe(false);
});

test('isDirectory returns true if dir exists', () => {
const exists = isDirectory('./src');
expect(exists).toBeTrue();
expect(exists).toBe(true);
});

test("isDirectory returns false if dir doesn't exist", () => {
const exists = isDirectory('./src-that-do-not-exist');
expect(exists).toBeFalse();
expect(exists).toBe(false);
});

test('createFile & copyFile create and copy a file', () => {
Expand All @@ -35,14 +35,14 @@ describe('Utils: file-system', () => {

// Create and copy file with createFile() and copyFile()
createFile({ file: file, content: content, verbose: false });
expect(isFile(file)).toBeTrue();
expect(isFile(file)).toBe(true);
copyFile({ source: file, target: copiedFile, verbose: false });
expect(isFile(copiedFile)).toBeTrue();
expect(isFile(copiedFile)).toBe(true);

// Ensure files are deleted
fs.rmSync(file);
fs.rmSync(copiedFile);
expect(isFile(file)).toBeFalse();
expect(isFile(copiedFile)).toBeFalse();
expect(isFile(file)).toBe(false);
expect(isFile(copiedFile)).toBe(false);
});
});
4 changes: 2 additions & 2 deletions test/utils/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Utils: object', () => {

test('Replaces a key value in a file', () => {
createFile({ file: testFile, content: testFileContent });
expect(isFile(testFile)).toBeTrue();
expect(isFile(testFile)).toBe(true);

replaceKeyValue(testFile, 'KEY1', 'VALUE10');
const replacedContent = fs.readFileSync(testFile, 'utf8');
Expand All @@ -27,7 +27,7 @@ describe('Utils: object', () => {

test("Replaces various keys' values in a file", () => {
createFile({ file: testFile, content: testFileContent });
expect(isFile(testFile)).toBeTrue();
expect(isFile(testFile)).toBe(true);

replaceKeysInFile(testFile, {
KEY1: 'VALUE_KEY1',
Expand Down
57 changes: 36 additions & 21 deletions test/utils/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,47 @@ import {
removeExtraSpaces,
} from '../../src/utils/string';

describe('Utils: string', () => {
test('first letter of a word is capitalized', () => {
const lowerWord = 'lowercase';
const capWord = capitalizeFirstLetter(lowerWord);
expect(capWord).toBeString();
expect(capWord).toEqual('Lowercase');
describe('Utils (string): hyphenToUnderscore', () => {
test('replaces hyphens with underscores', () => {
expect(hyphenToUnderscore('hello-world')).toBe('hello_world');
});

test('extra spaces are removed from a string', () => {
const sentence = ' this is a test ';
const noSpaceSentence = removeExtraSpaces(sentence);
expect(noSpaceSentence).toBeString();
expect(noSpaceSentence).toEqual('this is a test');
test('handles multiple hyphens', () => {
expect(hyphenToUnderscore('foo-bar-baz')).toBe('foo_bar_baz');
});

test('all break lines are removed from string', () => {
const sentence = '\nthis \nis \na \nanother \ntest\n';
const noSpaceSentence = removeBreakLines(sentence);
expect(noSpaceSentence).toBeString();
expect(noSpaceSentence).toEqual('this is a another test');
test('does not change words without hyphens', () => {
expect(hyphenToUnderscore('hello')).toBe('hello');
});
});

describe('Utils (string): capitalizeFirstLetter', () => {
test('capitalizes the first letter of a word', () => {
expect(capitalizeFirstLetter('hello')).toBe('Hello');
});

test('does not change an already capitalized word', () => {
expect(capitalizeFirstLetter('World')).toBe('World');
});
});

describe('Utils (string): removeExtraSpaces', () => {
test('removes extra spaces from the beginning and end', () => {
expect(removeExtraSpaces(' hello ')).toBe('hello');
});

test('replaces multiple spaces with a single space', () => {
expect(removeExtraSpaces('hello world')).toBe('hello world');
});
});

describe('Utils (string): removeBreakLines', () => {
test('removes break lines from text', () => {
expect(removeBreakLines('hello\nworld')).toBe('helloworld');
});

test('converts hypen to underscore', () => {
const string1 = 'my-word-with-multiple-hyphens-';
const stringUnderscore = hyphenToUnderscore(string1);
expect(stringUnderscore).toContain('_');
expect(stringUnderscore).toEqual('my_word_with_multiple_hyphens_');
test('handles different types of break lines', () => {
expect(removeBreakLines('hello\r\nworld')).toBe('helloworld');
expect(removeBreakLines('hello\rworld')).toBe('helloworld');
});
});
15 changes: 10 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
{
"compilerOptions": {
// Enable latest features
"lib": ["ESNext"],
"target": "ESNext",
"module": "ESNext",
"moduleDetection": "force",
"jsx": "react-jsx",
"allowJs": true,

/* Bundler mode */
"moduleResolution": "Bundler",
// Bundler mode
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"noEmit": true,

/* Linting */
"skipLibCheck": true,
// Best practices
"strict": true,
"skipLibCheck": true,
"noFallthroughCasesInSwitch": true,
"forceConsistentCasingInFileNames": true

// Some stricter flags (disabled by default)
"noUnusedLocals": false,
"noUnusedParameters": false,
"noPropertyAccessFromIndexSignature": false
}
}

0 comments on commit 07a8529

Please sign in to comment.