Skip to content

Commit

Permalink
test: fix tests on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
webdeveric committed Mar 25, 2024
1 parent 0250d05 commit d7963a3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 44 deletions.
90 changes: 48 additions & 42 deletions src/lib/ExportsProcessor.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { resolve, sep } from 'node:path';

import { describe, expect, it } from 'vitest';

import type { EntryPoint, PackageJson } from '@src/types.js';

import { ExportsProcessor } from './ExportsProcessor.js';

function fixSlash(input: string): string {
return input.replaceAll('/', sep);
}

describe('ExportsProcessor', () => {
describe('Gets EntryPoint[] from package.json exports', () => {
it('Works with ExportsEntryPath', () => {
Expand Down Expand Up @@ -52,31 +58,31 @@ describe('ExportsProcessor', () => {
condition: 'default',
type: demoPackageJson.type,
moduleName: demoPackageJson.name,
relativePath: 'index.js',
resolvedPath: '/tmp/index.js',
relativePath: fixSlash('index.js'),
resolvedPath: resolve('/tmp/index.js'),
fileName: 'index.js',
directory: '/tmp',
directory: resolve('/tmp'),
subpath: '.',
itemPath: ['exports', '.', 0, 'default'],
},
{
type: demoPackageJson.type,
moduleName: demoPackageJson.name,
relativePath: 'index.js',
resolvedPath: '/tmp/index.js',
relativePath: fixSlash('index.js'),
resolvedPath: resolve('/tmp/index.js'),
fileName: 'index.js',
directory: '/tmp',
directory: resolve('/tmp'),
subpath: '.',
condition: undefined,
itemPath: ['exports', '.', 1],
},
{
type: demoPackageJson.type,
moduleName: `${demoPackageJson.name}/package.json`,
relativePath: 'package.json',
resolvedPath: '/tmp/package.json',
relativePath: fixSlash('package.json'),
resolvedPath: resolve('/tmp/package.json'),
fileName: 'package.json',
directory: '/tmp',
directory: resolve('/tmp'),
subpath: './package.json',
condition: undefined,
itemPath: ['exports', './package.json'],
Expand Down Expand Up @@ -126,120 +132,120 @@ describe('ExportsProcessor', () => {
type: 'commonjs',
condition: 'types',
moduleName: demoPackageJson.name,
relativePath: 'dist/types/index.d.ts',
resolvedPath: '/tmp/dist/types/index.d.ts',
relativePath: fixSlash('dist/types/index.d.ts'),
resolvedPath: resolve('/tmp/dist/types/index.d.ts'),
fileName: 'index.d.ts',
directory: '/tmp/dist/types',
directory: resolve('/tmp/dist/types'),
subpath: '.',
itemPath: ['exports', '.', 'types'],
},
{
type: 'commonjs',
condition: 'require',
moduleName: demoPackageJson.name,
relativePath: 'dist/cjs/index.js',
resolvedPath: '/tmp/dist/cjs/index.js',
relativePath: fixSlash('dist/cjs/index.js'),
resolvedPath: resolve('/tmp/dist/cjs/index.js'),
fileName: 'index.js',
directory: '/tmp/dist/cjs',
directory: resolve('/tmp/dist/cjs'),
subpath: '.',
itemPath: ['exports', '.', 'require'],
},
{
type: 'module',
condition: 'import',
moduleName: demoPackageJson.name,
relativePath: 'dist/mjs/index.js',
resolvedPath: '/tmp/dist/mjs/index.js',
relativePath: fixSlash('dist/mjs/index.js'),
resolvedPath: resolve('/tmp/dist/mjs/index.js'),
fileName: 'index.js',
directory: '/tmp/dist/mjs',
directory: resolve('/tmp/dist/mjs'),
subpath: '.',
itemPath: ['exports', '.', 'import'],
},
{
type: 'commonjs',
condition: 'types',
moduleName: `${demoPackageJson.name}/*`,
relativePath: 'dist/types/*.d.ts',
resolvedPath: '/tmp/dist/types/*.d.ts',
relativePath: fixSlash('dist/types/*.d.ts'),
resolvedPath: resolve('/tmp/dist/types/*.d.ts'),
fileName: '*.d.ts',
directory: '/tmp/dist/types',
directory: resolve('/tmp/dist/types'),
subpath: './*',
itemPath: ['exports', './*', 'types'],
},
{
type: 'commonjs',
condition: 'require',
moduleName: `${demoPackageJson.name}/*`,
relativePath: 'dist/cjs/*.js',
resolvedPath: '/tmp/dist/cjs/*.js',
relativePath: fixSlash('dist/cjs/*.js'),
resolvedPath: resolve('/tmp/dist/cjs/*.js'),
fileName: '*.js',
directory: '/tmp/dist/cjs',
directory: resolve('/tmp/dist/cjs'),
subpath: './*',
itemPath: ['exports', './*', 'require'],
},
{
type: 'module',
condition: 'import',
moduleName: `${demoPackageJson.name}/*`,
relativePath: 'dist/mjs/*.js',
resolvedPath: '/tmp/dist/mjs/*.js',
relativePath: fixSlash('dist/mjs/*.js'),
resolvedPath: resolve('/tmp/dist/mjs/*.js'),
fileName: '*.js',
directory: '/tmp/dist/mjs',
directory: resolve('/tmp/dist/mjs'),
subpath: './*',
itemPath: ['exports', './*', 'import'],
},
{
type: 'commonjs',
condition: 'types',
moduleName: `${demoPackageJson.name}/sub-folder/*`,
relativePath: 'dist/types/sub-folder/*.d.ts',
resolvedPath: '/tmp/dist/types/sub-folder/*.d.ts',
relativePath: fixSlash('dist/types/sub-folder/*.d.ts'),
resolvedPath: resolve('/tmp/dist/types/sub-folder/*.d.ts'),
fileName: '*.d.ts',
directory: '/tmp/dist/types/sub-folder',
directory: resolve('/tmp/dist/types/sub-folder'),
subpath: './sub-folder/*',
itemPath: ['exports', './sub-folder/*', 'require', 'types'],
},
{
type: 'commonjs',
condition: 'require',
moduleName: `${demoPackageJson.name}/sub-folder/*`,
relativePath: 'dist/cjs/sub-folder/*.js',
resolvedPath: '/tmp/dist/cjs/sub-folder/*.js',
relativePath: fixSlash('dist/cjs/sub-folder/*.js'),
resolvedPath: resolve('/tmp/dist/cjs/sub-folder/*.js'),
fileName: '*.js',
directory: '/tmp/dist/cjs/sub-folder',
directory: resolve('/tmp/dist/cjs/sub-folder'),
subpath: './sub-folder/*',
itemPath: ['exports', './sub-folder/*', 'require', 'default'],
},
{
type: 'commonjs',
condition: 'types',
moduleName: `${demoPackageJson.name}/sub-folder/*`,
relativePath: 'dist/types/sub-folder/*.d.ts',
resolvedPath: '/tmp/dist/types/sub-folder/*.d.ts',
relativePath: fixSlash('dist/types/sub-folder/*.d.ts'),
resolvedPath: resolve('/tmp/dist/types/sub-folder/*.d.ts'),
fileName: '*.d.ts',
directory: '/tmp/dist/types/sub-folder',
directory: resolve('/tmp/dist/types/sub-folder'),
subpath: './sub-folder/*',
itemPath: ['exports', './sub-folder/*', 'import', 'types'],
},
{
type: 'module',
condition: 'import',
moduleName: `${demoPackageJson.name}/sub-folder/*`,
relativePath: 'dist/mjs/sub-folder/*.js',
resolvedPath: '/tmp/dist/mjs/sub-folder/*.js',
relativePath: fixSlash('dist/mjs/sub-folder/*.js'),
resolvedPath: resolve('/tmp/dist/mjs/sub-folder/*.js'),
fileName: '*.js',
directory: '/tmp/dist/mjs/sub-folder',
directory: resolve('/tmp/dist/mjs/sub-folder'),
subpath: './sub-folder/*',
itemPath: ['exports', './sub-folder/*', 'import', 'default'],
},
{
type: 'commonjs',
condition: undefined,
moduleName: `${demoPackageJson.name}/package.json`,
relativePath: 'package.json',
resolvedPath: '/tmp/package.json',
relativePath: fixSlash('package.json'),
resolvedPath: resolve('/tmp/package.json'),
fileName: 'package.json',
directory: '/tmp',
directory: resolve('/tmp'),
subpath: './package.json',
itemPath: ['exports', './package.json'],
},
Expand Down
6 changes: 4 additions & 2 deletions src/utils/resolveDirent.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'node:path';

import { describe, expect, it } from 'vitest';

import { resolveDirent } from './resolveDirent.js';
Expand All @@ -9,13 +11,13 @@ describe('resolveDirent()', () => {
name: 'test.js',
path: '/tmp',
}),
).toEqual('/tmp/test.js');
).toEqual(resolve('/tmp/test.js'));

expect(
resolveDirent({
name: 'test.js',
path: '/tmp/test.js',
}),
).toEqual('/tmp/test.js');
).toEqual(resolve('/tmp/test.js'));
});
});

0 comments on commit d7963a3

Please sign in to comment.