Skip to content

Commit

Permalink
Add tets for index, report, and utils files
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsobol committed Oct 13, 2024
1 parent d0bdc60 commit b13e354
Show file tree
Hide file tree
Showing 16 changed files with 877 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

node_modules
dist
coverage
package-lock.json

sonda-report.*
Expand Down
4 changes: 4 additions & 0 deletions packages/sonda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"CHANGELOG.md"
],
"scripts": {
"test": "vitest",
"test:coverage": "vitest run --coverage",
"prepack": "pnpm run build && clean-package -rm devDependencies scripts",
"build:load-source-map": "cd ../load-source-map && pnpm run build",
"build:html": "cd ../html-report && pnpm run build",
Expand All @@ -46,9 +48,11 @@
"open": "^10.1.0"
},
"devDependencies": {
"@vitest/coverage-v8": "2.1.2",
"esbuild": "^0.23.1",
"load-source-map": "workspace:^*",
"rollup": "^4.24.0",
"vitest": "^2.1.2",
"webpack": "^5.89.0"
}
}
12 changes: 5 additions & 7 deletions packages/sonda/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { relative, posix, sep } from 'path';
import path from 'path';
import type { Options } from './types';

const cwd = /* #__PURE__ */ process.cwd();

export function normalizeOptions( options?: Partial<Options> ) {
const defaultOptions: Options = {
open: true,
Expand All @@ -15,13 +13,13 @@ export function normalizeOptions( options?: Partial<Options> ) {
return Object.assign( {}, defaultOptions, options ) as Options;
}

export function normalizePath( path: string ): string {
export function normalizePath( pathToNormalize: string ): string {
// Unicode escape sequences used by Rollup and Vite to identify virtual modules
const normalized = path.replace( /^\0/, '' )
const normalized = pathToNormalize.replace( /^\0/, '' )

// Transform absolute paths to relative paths
const relativized = relative( cwd, normalized );
const relativized = path.relative( process.cwd(), normalized );

// Ensure paths are POSIX-compliant - https://stackoverflow.com/a/63251716/4617687
return relativized.replaceAll( sep, posix.sep );
return relativized.replaceAll( path.win32.sep, path.posix.sep );
}
2 changes: 2 additions & 0 deletions packages/sonda/tests/fixtures/detailed/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sonda/tests/fixtures/detailed/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/sonda/tests/fixtures/detailed/src/maths.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sonda/tests/fixtures/detailed/src/maths.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions packages/sonda/tests/fixtures/hasMapping/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sonda/tests/fixtures/hasMapping/index.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/sonda/tests/fixtures/hasMapping/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sonda/tests/fixtures/hasMapping/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions packages/sonda/tests/fixtures/noMapping/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function sum( a, b ) {
return a + b;
}
20 changes: 20 additions & 0 deletions packages/sonda/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, it, expect } from 'vitest';
import {
SondaEsbuildPlugin,
SondaRollupPlugin,
SondaWebpackPlugin,
} from '../src/index';

describe('index.ts', () => {
it( 'exports SondaEsbuildPlugin', () => {
expect( SondaEsbuildPlugin ).toBeDefined();
} );

it( 'exports SondaRollupPlugin', () => {
expect( SondaRollupPlugin ).toBeDefined();
} );

it( 'exports SondaWebpackPlugin', () => {
expect( SondaWebpackPlugin ).toBeDefined();
} );
} );
Loading

0 comments on commit b13e354

Please sign in to comment.