piral-cli 1.3.3-beta.6190 → 1.3.3-beta.6201

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/lib/bundler.js +25 -1
  2. package/lib/bundler.js.map +1 -1
  3. package/lib/cli.js +5 -2
  4. package/lib/cli.js.map +1 -1
  5. package/lib/commands.js +24 -1
  6. package/lib/commands.js.map +1 -1
  7. package/lib/common/io.js +5 -2
  8. package/lib/common/io.js.map +1 -1
  9. package/lib/common/log.js +24 -1
  10. package/lib/common/log.js.map +1 -1
  11. package/lib/common/npm.js +13 -13
  12. package/lib/common/npm.js.map +1 -1
  13. package/lib/external/index.js +426 -230
  14. package/lib/inject.js +24 -1
  15. package/lib/inject.js.map +1 -1
  16. package/lib/{common/clients → npm-clients}/bun.js +5 -5
  17. package/lib/npm-clients/bun.js.map +1 -0
  18. package/lib/{common/clients → npm-clients}/index.js +31 -8
  19. package/lib/npm-clients/index.js.map +1 -0
  20. package/lib/{common/clients → npm-clients}/lerna.js +4 -4
  21. package/lib/npm-clients/lerna.js.map +1 -0
  22. package/lib/{common/clients → npm-clients}/npm.js +4 -4
  23. package/lib/npm-clients/npm.js.map +1 -0
  24. package/lib/{common/clients → npm-clients}/pnp.js +4 -4
  25. package/lib/npm-clients/pnp.js.map +1 -0
  26. package/lib/{common/clients → npm-clients}/pnpm.js +4 -4
  27. package/lib/npm-clients/pnpm.js.map +1 -0
  28. package/lib/{common/clients → npm-clients}/rush.js +5 -5
  29. package/lib/npm-clients/rush.js.map +1 -0
  30. package/lib/{common/clients → npm-clients}/yarn.js +4 -4
  31. package/lib/npm-clients/yarn.js.map +1 -0
  32. package/package.json +2 -2
  33. package/src/apps/build-pilet.test.ts +1 -0
  34. package/src/apps/build-piral.test.ts +19 -12
  35. package/src/apps/new-pilet.test.ts +120 -76
  36. package/src/apps/new-piral.test.ts +100 -77
  37. package/src/apps/pack-pilet.test.ts +2 -3
  38. package/src/apps/upgrade-pilet.test.ts +1 -0
  39. package/src/bundler.test.ts +8 -7
  40. package/src/bundler.ts +2 -1
  41. package/src/cli.ts +1 -1
  42. package/src/common/archive.test.ts +10 -7
  43. package/src/common/browser.test.ts +2 -1
  44. package/src/common/compatibility.test.ts +1 -0
  45. package/src/common/envs.test.ts +2 -1
  46. package/src/common/hash.test.ts +1 -0
  47. package/src/common/http.test.ts +73 -70
  48. package/src/common/importmap.test.ts +3 -2
  49. package/src/common/info.test.ts +1 -0
  50. package/src/common/interactive.test.ts +2 -1
  51. package/src/common/io.ts +1 -1
  52. package/src/common/merge.test.ts +1 -0
  53. package/src/common/npm.test.ts +35 -37
  54. package/src/common/npm.ts +1 -1
  55. package/src/common/pack.test.ts +11 -10
  56. package/src/common/package.test.ts +131 -92
  57. package/src/common/parallel.test.ts +1 -0
  58. package/src/common/patches.test.ts +1 -0
  59. package/src/common/port.test.ts +2 -1
  60. package/src/common/rules.test.ts +4 -3
  61. package/src/common/url.test.ts +1 -0
  62. package/src/common/utils.test.ts +1 -0
  63. package/src/common/version.test.ts +1 -0
  64. package/src/external/index.test.ts +1 -0
  65. package/src/helpers.test.ts +1 -0
  66. package/src/injectors/pilet-injector.test.ts +6 -5
  67. package/src/injectors/piral-injector.test.ts +7 -6
  68. package/src/{common/clients → npm-clients}/bun.ts +5 -5
  69. package/src/{common/clients → npm-clients}/index.ts +1 -1
  70. package/src/{common/clients → npm-clients}/lerna.ts +4 -4
  71. package/src/{common/clients → npm-clients}/npm.ts +4 -4
  72. package/src/{common/clients → npm-clients}/pnp.ts +4 -4
  73. package/src/{common/clients → npm-clients}/pnpm.ts +4 -4
  74. package/src/{common/clients → npm-clients}/rush.ts +5 -5
  75. package/src/{common/clients → npm-clients}/yarn.ts +4 -4
  76. package/src/rules/pilet-has-externals-as-peers.test.ts +4 -3
  77. package/lib/common/clients/bun.js.map +0 -1
  78. package/lib/common/clients/index.js.map +0 -1
  79. package/lib/common/clients/lerna.js.map +0 -1
  80. package/lib/common/clients/npm.js.map +0 -1
  81. package/lib/common/clients/pnp.js.map +0 -1
  82. package/lib/common/clients/pnpm.js.map +0 -1
  83. package/lib/common/clients/rush.js.map +0 -1
  84. package/lib/common/clients/yarn.js.map +0 -1
  85. /package/lib/{common/clients → npm-clients}/bun.d.ts +0 -0
  86. /package/lib/{common/clients → npm-clients}/index.d.ts +0 -0
  87. /package/lib/{common/clients → npm-clients}/lerna.d.ts +0 -0
  88. /package/lib/{common/clients → npm-clients}/npm.d.ts +0 -0
  89. /package/lib/{common/clients → npm-clients}/pnp.d.ts +0 -0
  90. /package/lib/{common/clients → npm-clients}/pnpm.d.ts +0 -0
  91. /package/lib/{common/clients → npm-clients}/rush.d.ts +0 -0
  92. /package/lib/{common/clients → npm-clients}/yarn.d.ts +0 -0
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { mkdtempSync, existsSync, readFileSync } from 'fs';
2
3
  import { tmpdir } from 'os';
3
4
  import { join, resolve } from 'path';
@@ -7,8 +8,8 @@ function createTempDir() {
7
8
  return mkdtempSync(join(tmpdir(), 'piral-tests-new-piral-'));
8
9
  }
9
10
 
10
- jest.mock('../common/clients/npm', () => {
11
- const original = jest.requireActual('../common/clients/npm');
11
+ vitest.mock('../npm-clients/npm', async () => {
12
+ const original: any = await vitest.importActual('../npm-clients/npm');
12
13
 
13
14
  return {
14
15
  ...original,
@@ -18,87 +19,109 @@ jest.mock('../common/clients/npm', () => {
18
19
  };
19
20
  });
20
21
 
21
- jest.setTimeout(90000);
22
+ const testOptions = {
23
+ timeout: 60000,
24
+ };
22
25
 
23
26
  describe('New Piral Command', () => {
24
- it('scaffolding in an empty directory works', async () => {
25
- const dir = createTempDir();
26
- await newPiral(dir, { install: false });
27
- expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
28
- expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
29
- expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
30
- expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
31
- expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
32
- expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
33
- expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
34
- });
27
+ it(
28
+ 'scaffolding in an empty directory works',
29
+ async () => {
30
+ const dir = createTempDir();
31
+ await newPiral(dir, { install: false });
32
+ expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
33
+ expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
34
+ expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
35
+ expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
36
+ expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
37
+ expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
38
+ expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
39
+ },
40
+ testOptions,
41
+ );
35
42
 
36
- it('scaffolding with language JS works', async () => {
37
- const dir = createTempDir();
38
- await newPiral(dir, {
39
- language: 'js',
40
- install: false,
41
- });
42
- expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
43
- expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
44
- expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeFalsy();
45
- expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeTruthy();
46
- expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
47
- expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
48
- expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
49
- });
43
+ it(
44
+ 'scaffolding with language JS works',
45
+ async () => {
46
+ const dir = createTempDir();
47
+ await newPiral(dir, {
48
+ language: 'js',
49
+ install: false,
50
+ });
51
+ expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
52
+ expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
53
+ expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeFalsy();
54
+ expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeTruthy();
55
+ expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
56
+ expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
57
+ expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
58
+ },
59
+ testOptions,
60
+ );
50
61
 
51
- it('scaffolding with custom app name works', async () => {
52
- const dir = createTempDir();
53
- await newPiral(dir, {
54
- name: 'test-name',
55
- install: false,
56
- });
62
+ it(
63
+ 'scaffolding with custom app name works',
64
+ async () => {
65
+ const dir = createTempDir();
66
+ await newPiral(dir, {
67
+ name: 'test-name',
68
+ install: false,
69
+ });
57
70
 
58
- expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
59
- expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
60
- expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
61
- expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
62
- expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
63
- expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
64
- expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
71
+ expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeTruthy();
72
+ expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
73
+ expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
74
+ expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
75
+ expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
76
+ expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
77
+ expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
65
78
 
66
- const packageContent = await JSON.parse(readFileSync(`${dir}/package.json`, 'utf8'));
67
- expect(packageContent.name).toBe('test-name');
68
- });
79
+ const packageContent = await JSON.parse(readFileSync(`${dir}/package.json`, 'utf8'));
80
+ expect(packageContent.name).toBe('test-name');
81
+ },
82
+ testOptions,
83
+ );
69
84
 
70
- it('scaffolding for piral-core works', async () => {
71
- const dir = createTempDir();
72
- await newPiral(dir, {
73
- framework: 'piral-core',
74
- install: false,
75
- });
76
- expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeFalsy();
77
- expect(existsSync(resolve(dir, 'node_modules/piral-core/package.json'))).toBeTruthy();
78
- expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
79
- expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
80
- expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeFalsy();
81
- expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
82
- expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
83
- expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
84
- expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
85
- });
85
+ it(
86
+ 'scaffolding for piral-core works',
87
+ async () => {
88
+ const dir = createTempDir();
89
+ await newPiral(dir, {
90
+ framework: 'piral-core',
91
+ install: false,
92
+ });
93
+ expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeFalsy();
94
+ expect(existsSync(resolve(dir, 'node_modules/piral-core/package.json'))).toBeTruthy();
95
+ expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
96
+ expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
97
+ expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeFalsy();
98
+ expect(existsSync(resolve(dir, 'src/index.tsx'))).toBeTruthy();
99
+ expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
100
+ expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
101
+ expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
102
+ },
103
+ testOptions,
104
+ );
86
105
 
87
- it('scaffolding for piral-base works', async () => {
88
- const dir = createTempDir();
89
- await newPiral(dir, {
90
- framework: 'piral-base',
91
- install: false,
92
- });
93
- expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeFalsy();
94
- expect(existsSync(resolve(dir, 'node_modules/piral-core/package.json'))).toBeFalsy();
95
- expect(existsSync(resolve(dir, 'node_modules/piral-base/package.json'))).toBeTruthy();
96
- expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
97
- expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
98
- expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeFalsy();
99
- expect(existsSync(resolve(dir, 'src/index.ts'))).toBeTruthy();
100
- expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
101
- expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
102
- expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
103
- });
106
+ it(
107
+ 'scaffolding for piral-base works',
108
+ async () => {
109
+ const dir = createTempDir();
110
+ await newPiral(dir, {
111
+ framework: 'piral-base',
112
+ install: false,
113
+ });
114
+ expect(existsSync(resolve(dir, 'node_modules/piral/package.json'))).toBeFalsy();
115
+ expect(existsSync(resolve(dir, 'node_modules/piral-core/package.json'))).toBeFalsy();
116
+ expect(existsSync(resolve(dir, 'node_modules/piral-base/package.json'))).toBeTruthy();
117
+ expect(existsSync(resolve(dir, 'package.json'))).toBeTruthy();
118
+ expect(existsSync(resolve(dir, 'tsconfig.json'))).toBeTruthy();
119
+ expect(existsSync(resolve(dir, 'src/index.jsx'))).toBeFalsy();
120
+ expect(existsSync(resolve(dir, 'src/index.ts'))).toBeTruthy();
121
+ expect(existsSync(resolve(dir, 'src/index.html'))).toBeTruthy();
122
+ expect(existsSync(resolve(dir, 'src/mocks/backend.js'))).toBeTruthy();
123
+ expect(existsSync(resolve(dir, '.npmrc'))).toBeFalsy();
124
+ },
125
+ testOptions,
126
+ );
104
127
  });
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { mkdtempSync, existsSync, writeFileSync } from 'fs';
2
3
  import { tmpdir } from 'os';
3
4
  import { join, resolve } from 'path';
@@ -40,11 +41,9 @@ describe('Pack Pilet Command', () => {
40
41
  }),
41
42
  'utf8',
42
43
  );
43
- process.chdir(dir);
44
44
 
45
- await packPilet();
45
+ await packPilet(dir);
46
46
 
47
- process.chdir(originalDir);
48
47
  expect(existsSync(resolve(dir, 'my-pilet-1.0.0.tgz'))).toBeTruthy();
49
48
  });
50
49
 
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { mkdtempSync } from 'fs';
2
3
  import { tmpdir } from 'os';
3
4
  import { join } from 'path';
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import {
2
3
  setBundler,
3
4
  callPiletBuild,
@@ -13,20 +14,20 @@ const defaults = {
13
14
  bundler: false,
14
15
  };
15
16
 
16
- jest.mock('./build/bundler-calls.ts', () => ({
17
- callDynamic: jest.fn(() =>
17
+ vitest.mock('./build/bundler-calls.ts', () => ({
18
+ callDynamic: vitest.fn(() =>
18
19
  Promise.resolve({
19
20
  bundle: {},
20
21
  }),
21
22
  ),
22
- callStatic: jest.fn(() =>
23
+ callStatic: vitest.fn(() =>
23
24
  Promise.resolve({
24
25
  bundle: {},
25
26
  }),
26
27
  ),
27
28
  }));
28
29
 
29
- jest.mock('./inject', () => ({
30
+ vitest.mock('./inject', () => ({
30
31
  inject() {
31
32
  if (defaults.bundler) {
32
33
  setBundler({
@@ -43,7 +44,7 @@ jest.mock('./inject', () => ({
43
44
  },
44
45
  }));
45
46
 
46
- jest.mock('./common', () => ({
47
+ vitest.mock('./common', () => ({
47
48
  config: {
48
49
  bundler: 'parcel',
49
50
  },
@@ -51,7 +52,7 @@ jest.mock('./common', () => ({
51
52
  return Promise.resolve(defval);
52
53
  },
53
54
  compatVersion: '1',
54
- installNpmPackage: jest.fn(),
55
+ installNpmPackage: vitest.fn(),
55
56
  fail(msg) {
56
57
  throw new Error(msg);
57
58
  },
@@ -60,7 +61,7 @@ jest.mock('./common', () => ({
60
61
  determineNpmClient() {
61
62
  return 'npm';
62
63
  },
63
- patchModules: jest.fn(),
64
+ patchModules: vitest.fn(),
64
65
  logReset() {},
65
66
  }));
66
67
 
package/src/bundler.ts CHANGED
@@ -57,7 +57,8 @@ async function installDefaultBundler(root: string) {
57
57
  await installNpmPackage(client, packageId, root, '--save-dev', '--save-exact');
58
58
  log('generalDebug_0003', `Installed bundler from "${selectedPackage}".`);
59
59
 
60
- require('./inject').inject(selectedPackage);
60
+ const { inject } = await import('./inject');
61
+ inject(selectedPackage);
61
62
  }
62
63
 
63
64
  function checkDefaultBundler(bundler: QualifiedBundler) {
package/src/cli.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as yargs from 'yargs';
1
+ import yargs from 'yargs';
2
2
  import { detailed } from 'yargs-parser';
3
3
  import { caterpillerIcon, zapIcon, butterflyIcon, cliName, cliVersion } from './common';
4
4
  import { runQuestionnaireFor } from './questionnaire';
@@ -1,4 +1,5 @@
1
- import { createTarball, unpackTarball, unpackGzTar } from './archive';
1
+ import { describe, it, expect, vitest } from 'vitest';
2
+ import { createTarball, unpackTarball } from './archive';
2
3
  import { Stream, Readable } from 'stream';
3
4
 
4
5
  class ReadableString extends Readable {
@@ -32,21 +33,23 @@ interface ExtractOptions {
32
33
  keep: boolean;
33
34
  }
34
35
 
35
- jest.mock('path', () =>
36
- // extend the auto mock of path
37
- Object.assign(jest.genMockFromModule('path'), {
36
+ vitest.mock('path', async () => {
37
+ const original = await vitest.importActual('path') as any;
38
+
39
+ return {
40
+ ...original,
38
41
  relative: (from: string, to: string) => {
39
42
  return to;
40
43
  },
41
44
  resolve: (...pathSegments: string[]) => {
42
45
  return pathSegments[1];
43
46
  },
44
- }),
45
- );
47
+ };
48
+ });
46
49
 
47
50
  const fileNotFoundError = 'File not found!';
48
51
 
49
- jest.mock('../external', () => ({
52
+ vitest.mock('../external', () => ({
50
53
  ora() {
51
54
  return {};
52
55
  },
@@ -1,8 +1,9 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { openBrowser } from './browser';
2
3
 
3
4
  let error = false;
4
5
 
5
- jest.mock('../external', () => ({
6
+ vitest.mock('../external', () => ({
6
7
  rc(_, cfg) {
7
8
  return cfg;
8
9
  },
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { checkAppShellCompatibility } from './compatibility';
2
3
  import { cliVersion } from './info';
3
4
 
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest, beforeEach, afterEach } from 'vitest';
1
2
  import { resolve } from 'path';
2
3
  import { setStandardEnvs } from './envs';
3
4
 
@@ -7,7 +8,7 @@ describe('Environment Module', () => {
7
8
  const oldEnv = process.env;
8
9
 
9
10
  beforeEach(() => {
10
- jest.resetModules();
11
+ vitest.resetModules();
11
12
  process.env = {};
12
13
  });
13
14
 
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { computeHash, computeMd5 } from './hash';
2
3
 
3
4
  describe('Hash Module', () => {
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { postFile, downloadFile } from './http';
2
3
 
3
4
  const apiUrl = 'http://sample.fooo.com/api/v1/pilet';
@@ -7,79 +8,81 @@ let errorOther = false;
7
8
  let errorResponse = false;
8
9
  let errorResponse2 = false;
9
10
 
10
- jest.mock('../external', () => ({
11
- rc(_, cfg) {
12
- return cfg;
13
- },
14
- ora() {
15
- return {
16
- warn() {},
17
- fail() {},
18
- };
19
- },
20
- axios: {
21
- default: {
22
- post(url, _, options) {
23
- const found = url === apiUrl;
24
- const auth = options.headers.authorization === 'Basic 123';
11
+ vitest.mock('../external', async () => {
12
+ return {
13
+ rc(_, cfg) {
14
+ return cfg;
15
+ },
16
+ ora() {
17
+ return {
18
+ warn() {},
19
+ fail() {},
20
+ };
21
+ },
22
+ axios: {
23
+ default: {
24
+ post(url, _, options) {
25
+ const found = url === apiUrl;
26
+ const auth = options.headers.authorization === 'Basic 123';
25
27
 
26
- if (errorRequest) {
27
- return Promise.reject({
28
- request: {},
29
- });
30
- } else if (errorOther) {
31
- return Promise.reject({
32
- message: 'error',
33
- });
34
- } else if (errorResponse) {
35
- return Promise.reject({
36
- response: {
37
- status: 410,
38
- statusText: 'Not Gone',
39
- data: '{ "message": "This component is not available anymore." }',
40
- },
41
- });
42
- } else if (errorResponse2) {
43
- return Promise.reject({
44
- response: {
45
- status: 410,
46
- statusText: 'Not Gone',
47
- data: { message: 'This component is not available anymore.' },
48
- },
49
- });
50
- } else if (!found) {
51
- return Promise.reject({
52
- response: {
53
- status: 404,
54
- statusText: 'Not found',
55
- },
56
- });
57
- } else if (!auth) {
58
- return Promise.reject({
59
- response: {
60
- status: 401,
61
- statusText: 'Not authorized',
62
- },
63
- });
64
- } else {
65
- return Promise.resolve({
66
- status: 200,
67
- statusText: 'OK',
68
- });
69
- }
70
- },
71
- get(url, options) {
72
- if (errorOther) {
73
- return Promise.reject({
74
- message: 'error',
75
- });
76
- }
77
- return Promise.resolve({ data: 'test' });
28
+ if (errorRequest) {
29
+ return Promise.reject({
30
+ request: {},
31
+ });
32
+ } else if (errorOther) {
33
+ return Promise.reject({
34
+ message: 'error',
35
+ });
36
+ } else if (errorResponse) {
37
+ return Promise.reject({
38
+ response: {
39
+ status: 410,
40
+ statusText: 'Not Gone',
41
+ data: '{ "message": "This component is not available anymore." }',
42
+ },
43
+ });
44
+ } else if (errorResponse2) {
45
+ return Promise.reject({
46
+ response: {
47
+ status: 410,
48
+ statusText: 'Not Gone',
49
+ data: { message: 'This component is not available anymore.' },
50
+ },
51
+ });
52
+ } else if (!found) {
53
+ return Promise.reject({
54
+ response: {
55
+ status: 404,
56
+ statusText: 'Not found',
57
+ },
58
+ });
59
+ } else if (!auth) {
60
+ return Promise.reject({
61
+ response: {
62
+ status: 401,
63
+ statusText: 'Not authorized',
64
+ },
65
+ });
66
+ } else {
67
+ return Promise.resolve({
68
+ status: 200,
69
+ statusText: 'OK',
70
+ });
71
+ }
72
+ },
73
+ get(url, options) {
74
+ if (errorOther) {
75
+ return Promise.reject({
76
+ message: 'error',
77
+ });
78
+ }
79
+ return Promise.resolve({ data: 'test' });
80
+ },
78
81
  },
79
82
  },
80
- },
81
- FormData: jest.requireActual('form-data'),
82
- }));
83
+ FormData: (await vitest.importActual('form-data') as any).default,
84
+ };
85
+ });
83
86
 
84
87
  describe('HTTP Module', () => {
85
88
  it('postFile form posts a file successfully should be ok', async () => {
@@ -1,6 +1,7 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { readImportmap } from './importmap';
2
3
 
3
- jest.mock('./npm', () => ({
4
+ vitest.mock('./npm', () => ({
4
5
  tryResolvePackage(id, dir) {
5
6
  if (id === 'qxz') {
6
7
  return undefined;
@@ -45,7 +46,7 @@ const mockPackages = {
45
46
  },
46
47
  };
47
48
 
48
- jest.mock('./io', () => ({
49
+ vitest.mock('./io', () => ({
49
50
  checkIsDirectory() {},
50
51
  getHash() {},
51
52
  readJson(dir) {
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { findCompatVersion } from './info';
2
3
 
3
4
  describe('CLI info module', () => {
@@ -1,8 +1,9 @@
1
+ import { describe, it, expect, vitest } from 'vitest';
1
2
  import { promptConfirm, promptSelect } from './interactive';
2
3
 
3
4
  const answer = 'Yes, really';
4
5
 
5
- jest.mock('../external', () => ({
6
+ vitest.mock('../external', () => ({
6
7
  rc(_, cfg) {
7
8
  return cfg;
8
9
  },
package/src/common/io.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as rimraf from 'rimraf';
1
+ import rimraf from 'rimraf';
2
2
  import { transpileModule, ModuleKind, ModuleResolutionKind, ScriptTarget, JsxEmit } from 'typescript';
3
3
  import { join, resolve, basename, dirname, extname } from 'path';
4
4
  import { exists, lstat, unlink, statSync } from 'fs';
@@ -1,3 +1,4 @@
1
+ import { describe, it, expect } from 'vitest';
1
2
  import { deepMerge } from './merge';
2
3
 
3
4
  describe('Merge Module', () => {