@netlify/edge-bundler 14.8.2 → 14.8.4
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.
- package/dist/node/bridge.d.ts +1 -1
- package/dist/node/bridge.js +3 -3
- package/dist/node/bundler.js +41 -46
- package/dist/node/config.js +6 -1
- package/dist/node/feature_flags.js +1 -1
- package/dist/node/formats/eszip.d.ts +0 -4
- package/dist/node/formats/eszip.js +0 -11
- package/package.json +4 -3
- package/deno/extract.ts +0 -7
- package/dist/node/bridge.test.js +0 -141
- package/dist/node/bundler.test.js +0 -717
- package/dist/node/config.test.js +0 -408
- package/dist/node/declaration.test.js +0 -131
- package/dist/node/deploy_config.test.js +0 -48
- package/dist/node/downloader.test.js +0 -124
- package/dist/node/finder.test.js +0 -17
- package/dist/node/import_map.test.js +0 -212
- package/dist/node/logger.test.js +0 -51
- package/dist/node/main.test.js +0 -46
- package/dist/node/manifest.test.js +0 -597
- package/dist/node/package_json.test.js +0 -7
- package/dist/node/server/server.test.js +0 -144
- package/dist/node/stage_2.test.js +0 -53
- package/dist/node/types.test.js +0 -63
- package/dist/node/validation/manifest/index.test.js +0 -237
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { rm } from 'fs/promises';
|
|
2
|
-
import { platform } from 'process';
|
|
3
|
-
import { PassThrough } from 'stream';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
|
-
import nock from 'nock';
|
|
6
|
-
import tmp from 'tmp-promise';
|
|
7
|
-
import { beforeEach, afterEach, test, expect, vi } from 'vitest';
|
|
8
|
-
import { fixturesDir, testLogger } from '../test/util.js';
|
|
9
|
-
import { download } from './downloader.js';
|
|
10
|
-
import { getPlatformTarget } from './platform.js';
|
|
11
|
-
// This changes the defaults for p-retry
|
|
12
|
-
// minTimeout 1000 -> 10
|
|
13
|
-
// factor 2 -> 1
|
|
14
|
-
// This reduces the wait time in the tests from `2s, 4s, 8s` to `10ms, 10ms, 10ms` for 3 retries
|
|
15
|
-
vi.mock('p-retry', async (importOriginal) => {
|
|
16
|
-
const pRetry = (await importOriginal());
|
|
17
|
-
return {
|
|
18
|
-
default: (func, options) => pRetry.default(func, { minTimeout: 10, factor: 1, ...options }),
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
const streamError = () => {
|
|
22
|
-
const stream = new PassThrough();
|
|
23
|
-
setTimeout(() => stream.emit('data', 'zipcontent'), 100);
|
|
24
|
-
setTimeout(() => stream.emit('error', new Error('stream error')), 200);
|
|
25
|
-
return stream;
|
|
26
|
-
};
|
|
27
|
-
beforeEach(async (ctx) => {
|
|
28
|
-
const tmpDir = await tmp.dir();
|
|
29
|
-
ctx.tmpDir = tmpDir.path;
|
|
30
|
-
});
|
|
31
|
-
afterEach(async (ctx) => {
|
|
32
|
-
await rm(ctx.tmpDir, { force: true, recursive: true, maxRetries: 10 });
|
|
33
|
-
});
|
|
34
|
-
test('tries downloading binary up to 4 times', async (ctx) => {
|
|
35
|
-
nock.disableNetConnect();
|
|
36
|
-
const version = '99.99.99';
|
|
37
|
-
const mockURL = 'https://dl.deno.land:443';
|
|
38
|
-
const target = getPlatformTarget();
|
|
39
|
-
const zipPath = `/release/v${version}/deno-${target}.zip`;
|
|
40
|
-
const latestVersionMock = nock(mockURL)
|
|
41
|
-
.get('/release-latest.txt')
|
|
42
|
-
.reply(200, `v${version}\n`)
|
|
43
|
-
// first attempt
|
|
44
|
-
.get(zipPath)
|
|
45
|
-
.reply(500)
|
|
46
|
-
// second attempt
|
|
47
|
-
.get(zipPath)
|
|
48
|
-
.reply(500)
|
|
49
|
-
// third attempt
|
|
50
|
-
.get(zipPath)
|
|
51
|
-
.reply(500)
|
|
52
|
-
// fourth attempt
|
|
53
|
-
.get(zipPath)
|
|
54
|
-
// 1 second delay
|
|
55
|
-
.delayBody(1000)
|
|
56
|
-
.replyWithFile(200, platform === 'win32' ? `${fixturesDir}/deno.win.zip` : `${fixturesDir}/deno.zip`, {
|
|
57
|
-
'Content-Type': 'application/zip',
|
|
58
|
-
});
|
|
59
|
-
const deno = await download(ctx.tmpDir, `^${version}`, testLogger);
|
|
60
|
-
expect(latestVersionMock.isDone()).toBe(true);
|
|
61
|
-
expect(deno).toBeTruthy();
|
|
62
|
-
const res = await execa(deno);
|
|
63
|
-
expect(res.stdout).toBe('hello');
|
|
64
|
-
});
|
|
65
|
-
test('fails downloading binary after 4th time', async (ctx) => {
|
|
66
|
-
expect.assertions(2);
|
|
67
|
-
nock.disableNetConnect();
|
|
68
|
-
const version = '99.99.99';
|
|
69
|
-
const mockURL = 'https://dl.deno.land:443';
|
|
70
|
-
const target = getPlatformTarget();
|
|
71
|
-
const zipPath = `/release/v${version}/deno-${target}.zip`;
|
|
72
|
-
const latestVersionMock = nock(mockURL)
|
|
73
|
-
.get('/release-latest.txt')
|
|
74
|
-
.reply(200, `v${version}\n`)
|
|
75
|
-
// first attempt
|
|
76
|
-
.get(zipPath)
|
|
77
|
-
.reply(500)
|
|
78
|
-
// second attempt
|
|
79
|
-
.get(zipPath)
|
|
80
|
-
.reply(500)
|
|
81
|
-
// third attempt
|
|
82
|
-
.get(zipPath)
|
|
83
|
-
.reply(500)
|
|
84
|
-
// fourth attempt
|
|
85
|
-
.get(zipPath)
|
|
86
|
-
.reply(500);
|
|
87
|
-
try {
|
|
88
|
-
await download(ctx.tmpDir, `^${version}`, testLogger);
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
expect(error.message).toMatch(/Download failed with status code 500/);
|
|
92
|
-
}
|
|
93
|
-
expect(latestVersionMock.isDone()).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
test('fails downloading if response stream throws error', async (ctx) => {
|
|
96
|
-
expect.assertions(2);
|
|
97
|
-
nock.disableNetConnect();
|
|
98
|
-
const version = '99.99.99';
|
|
99
|
-
const mockURL = 'https://dl.deno.land:443';
|
|
100
|
-
const target = getPlatformTarget();
|
|
101
|
-
const zipPath = `/release/v${version}/deno-${target}.zip`;
|
|
102
|
-
const latestVersionMock = nock(mockURL)
|
|
103
|
-
.get('/release-latest.txt')
|
|
104
|
-
.reply(200, `v${version}\n`)
|
|
105
|
-
// first attempt
|
|
106
|
-
.get(zipPath)
|
|
107
|
-
.reply(200, streamError)
|
|
108
|
-
// second attempt
|
|
109
|
-
.get(zipPath)
|
|
110
|
-
.reply(200, streamError)
|
|
111
|
-
// third attempt
|
|
112
|
-
.get(zipPath)
|
|
113
|
-
.reply(200, streamError)
|
|
114
|
-
// fourth attempt
|
|
115
|
-
.get(zipPath)
|
|
116
|
-
.reply(200, streamError);
|
|
117
|
-
try {
|
|
118
|
-
await download(ctx.tmpDir, `^${version}`, testLogger);
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
expect(error.message).toMatch(/stream error/);
|
|
122
|
-
}
|
|
123
|
-
expect(latestVersionMock.isDone()).toBe(true);
|
|
124
|
-
});
|
package/dist/node/finder.test.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { test, expect } from 'vitest';
|
|
2
|
-
import { removeDuplicatesByExtension } from './finder.js';
|
|
3
|
-
test('filters out any duplicate files based on the extension', () => {
|
|
4
|
-
const functions = [
|
|
5
|
-
'file1.js',
|
|
6
|
-
'file1.ts',
|
|
7
|
-
'file2.tsx',
|
|
8
|
-
'file2.jsx',
|
|
9
|
-
'file3.tsx',
|
|
10
|
-
'file3.js',
|
|
11
|
-
'file4.ts',
|
|
12
|
-
'file5.ts',
|
|
13
|
-
'file5.tsx',
|
|
14
|
-
];
|
|
15
|
-
const expected = ['file1.js', 'file2.jsx', 'file3.js', 'file4.ts', 'file5.ts'];
|
|
16
|
-
expect(removeDuplicatesByExtension(functions)).toStrictEqual(expected);
|
|
17
|
-
});
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from 'fs';
|
|
2
|
-
import { join } from 'path';
|
|
3
|
-
import { cwd } from 'process';
|
|
4
|
-
import { pathToFileURL } from 'url';
|
|
5
|
-
import tmp from 'tmp-promise';
|
|
6
|
-
import { describe, test, expect } from 'vitest';
|
|
7
|
-
import { ImportMap } from './import_map.js';
|
|
8
|
-
import { getLogger } from './logger.js';
|
|
9
|
-
test('Handles import maps with full URLs without specifying a base URL', () => {
|
|
10
|
-
const basePath = join(cwd(), 'my-cool-site', 'import-map.json');
|
|
11
|
-
const inputFile1 = {
|
|
12
|
-
baseURL: pathToFileURL(basePath),
|
|
13
|
-
imports: {
|
|
14
|
-
'alias:jamstack': 'https://jamstack.org',
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
const inputFile2 = {
|
|
18
|
-
baseURL: pathToFileURL(basePath),
|
|
19
|
-
imports: {
|
|
20
|
-
'alias:pets': 'https://petsofnetlify.com/',
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
const map = new ImportMap([inputFile1, inputFile2]);
|
|
24
|
-
const m1 = map.getContents();
|
|
25
|
-
expect(m1.imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy');
|
|
26
|
-
expect(m1.imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts');
|
|
27
|
-
expect(m1.imports['alias:jamstack']).toBe('https://jamstack.org/');
|
|
28
|
-
expect(m1.imports['alias:pets']).toBe('https://petsofnetlify.com/');
|
|
29
|
-
const m2 = map.getContentsWithURLObjects();
|
|
30
|
-
expect(m2.imports['netlify:edge']).toStrictEqual(new URL('https://edge.netlify.com/v1/index.ts?v=legacy'));
|
|
31
|
-
expect(m2.imports['@netlify/edge-functions']).toStrictEqual(new URL('https://edge.netlify.com/v1/index.ts'));
|
|
32
|
-
expect(m2.imports['alias:jamstack']).toStrictEqual(new URL('https://jamstack.org/'));
|
|
33
|
-
expect(m2.imports['alias:pets']).toStrictEqual(new URL('https://petsofnetlify.com/'));
|
|
34
|
-
});
|
|
35
|
-
test('Resolves relative paths to absolute paths if a base path is not provided', () => {
|
|
36
|
-
const basePath = join(cwd(), 'my-cool-site', 'import-map.json');
|
|
37
|
-
const inputFile1 = {
|
|
38
|
-
baseURL: pathToFileURL(basePath),
|
|
39
|
-
imports: {
|
|
40
|
-
'alias:pets': './heart/pets/',
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
const map = new ImportMap([inputFile1]);
|
|
44
|
-
const expectedPath = join(cwd(), 'my-cool-site', 'heart', 'pets');
|
|
45
|
-
const m1 = map.getContents();
|
|
46
|
-
expect(m1.imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy');
|
|
47
|
-
expect(m1.imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts');
|
|
48
|
-
expect(m1.imports['alias:pets']).toBe(`${pathToFileURL(expectedPath).toString()}/`);
|
|
49
|
-
const m2 = map.getContentsWithURLObjects();
|
|
50
|
-
expect(m2.imports['netlify:edge']).toStrictEqual(new URL('https://edge.netlify.com/v1/index.ts?v=legacy'));
|
|
51
|
-
expect(m2.imports['@netlify/edge-functions']).toStrictEqual(new URL('https://edge.netlify.com/v1/index.ts'));
|
|
52
|
-
expect(m2.imports['alias:pets']).toStrictEqual(new URL(`${pathToFileURL(expectedPath).toString()}/`));
|
|
53
|
-
});
|
|
54
|
-
describe('Returns the fully resolved import map', () => {
|
|
55
|
-
const inputFile1 = {
|
|
56
|
-
baseURL: new URL('file:///some/full/path/import-map.json'),
|
|
57
|
-
imports: {
|
|
58
|
-
specifier1: 'file:///some/full/path/file.js',
|
|
59
|
-
specifier2: './file2.js',
|
|
60
|
-
specifier3: 'file:///different/full/path/file3.js',
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
const inputFile2 = {
|
|
64
|
-
baseURL: new URL('file:///some/cool/path/import-map.json'),
|
|
65
|
-
imports: {
|
|
66
|
-
'lib/*': './library/',
|
|
67
|
-
},
|
|
68
|
-
scopes: {
|
|
69
|
-
'with/scopes/': {
|
|
70
|
-
'lib/*': 'https://external.netlify/lib/',
|
|
71
|
-
foo: './foo-alias',
|
|
72
|
-
bar: 'file:///different/full/path/bar.js',
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
test('Without prefixes', () => {
|
|
77
|
-
const map = new ImportMap([inputFile1, inputFile2]);
|
|
78
|
-
const { imports, scopes } = map.getContents();
|
|
79
|
-
expect(imports).toStrictEqual({
|
|
80
|
-
'lib/*': 'file:///some/cool/path/library/',
|
|
81
|
-
specifier3: 'file:///different/full/path/file3.js',
|
|
82
|
-
specifier2: 'file:///some/full/path/file2.js',
|
|
83
|
-
specifier1: 'file:///some/full/path/file.js',
|
|
84
|
-
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
|
|
85
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy',
|
|
86
|
-
});
|
|
87
|
-
expect(scopes).toStrictEqual({
|
|
88
|
-
'file:///some/cool/path/with/scopes/': {
|
|
89
|
-
'lib/*': 'https://external.netlify/lib/',
|
|
90
|
-
foo: 'file:///some/cool/path/foo-alias',
|
|
91
|
-
bar: 'file:///different/full/path/bar.js',
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
test('With prefixes', () => {
|
|
96
|
-
const map = new ImportMap([inputFile1, inputFile2]);
|
|
97
|
-
const { imports, scopes } = map.getContents({
|
|
98
|
-
'file:///some/': 'file:///root/',
|
|
99
|
-
'file:///different/': 'file:///vendor/',
|
|
100
|
-
});
|
|
101
|
-
expect(imports).toStrictEqual({
|
|
102
|
-
'lib/*': 'file:///root/cool/path/library/',
|
|
103
|
-
specifier3: 'file:///vendor/full/path/file3.js',
|
|
104
|
-
specifier2: 'file:///root/full/path/file2.js',
|
|
105
|
-
specifier1: 'file:///root/full/path/file.js',
|
|
106
|
-
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
|
|
107
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy',
|
|
108
|
-
});
|
|
109
|
-
expect(scopes).toStrictEqual({
|
|
110
|
-
'file:///root/cool/path/with/scopes/': {
|
|
111
|
-
'lib/*': 'https://external.netlify/lib/',
|
|
112
|
-
foo: 'file:///root/cool/path/foo-alias',
|
|
113
|
-
bar: 'file:///vendor/full/path/bar.js',
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
test('Throws when an import map uses a relative path to reference a file outside of the base path', () => {
|
|
119
|
-
const inputFile1 = {
|
|
120
|
-
baseURL: pathToFileURL(join(cwd(), 'import-map.json')),
|
|
121
|
-
imports: {
|
|
122
|
-
'alias:file': '../file.js',
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
const map = new ImportMap([inputFile1], cwd());
|
|
126
|
-
expect(() => map.getContents()).toThrowError(`Import map cannot reference '${join(cwd(), '..', 'file.js')}' as it's outside of the base directory '${cwd()}'`);
|
|
127
|
-
});
|
|
128
|
-
test('Writes import map file to disk', async () => {
|
|
129
|
-
const file = await tmp.file();
|
|
130
|
-
const basePath = join(cwd(), 'my-cool-site', 'import-map.json');
|
|
131
|
-
const inputFile1 = {
|
|
132
|
-
baseURL: pathToFileURL(basePath),
|
|
133
|
-
imports: {
|
|
134
|
-
'alias:pets': './heart/pets/file.ts',
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
const map = new ImportMap([inputFile1]);
|
|
138
|
-
await map.writeToFile(file.path);
|
|
139
|
-
const createdFile = await fs.readFile(file.path, 'utf8');
|
|
140
|
-
const { imports } = JSON.parse(createdFile);
|
|
141
|
-
const expectedPath = join(cwd(), 'my-cool-site', 'heart', 'pets', 'file.ts');
|
|
142
|
-
await file.cleanup();
|
|
143
|
-
expect(imports['netlify:edge']).toBe('https://edge.netlify.com/v1/index.ts?v=legacy');
|
|
144
|
-
expect(imports['@netlify/edge-functions']).toBe('https://edge.netlify.com/v1/index.ts');
|
|
145
|
-
expect(imports['alias:pets']).toBe(pathToFileURL(expectedPath).toString());
|
|
146
|
-
});
|
|
147
|
-
test('Respects import map when it has only scoped key', async () => {
|
|
148
|
-
const file = await tmp.file();
|
|
149
|
-
const importMap = {
|
|
150
|
-
scopes: {
|
|
151
|
-
'./foo': {
|
|
152
|
-
'alias:pets': './heart/pets/file.ts',
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
await fs.writeFile(file.path, JSON.stringify(importMap));
|
|
157
|
-
const map = new ImportMap();
|
|
158
|
-
await map.addFile(file.path, getLogger());
|
|
159
|
-
expect(map.getContents()).toEqual({
|
|
160
|
-
imports: {
|
|
161
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy',
|
|
162
|
-
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
|
|
163
|
-
},
|
|
164
|
-
scopes: {
|
|
165
|
-
[pathToFileURL(join(file.path, '../foo')).href]: {
|
|
166
|
-
'alias:pets': pathToFileURL(join(file.path, '../heart/pets/file.ts')).href,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
test('Clones an import map', () => {
|
|
172
|
-
const basePath = join(cwd(), 'my-cool-site', 'import-map.json');
|
|
173
|
-
const inputFile1 = {
|
|
174
|
-
baseURL: pathToFileURL(basePath),
|
|
175
|
-
imports: {
|
|
176
|
-
'alias:jamstack': 'https://jamstack.org',
|
|
177
|
-
},
|
|
178
|
-
};
|
|
179
|
-
const inputFile2 = {
|
|
180
|
-
baseURL: pathToFileURL(basePath),
|
|
181
|
-
imports: {
|
|
182
|
-
'alias:pets': 'https://petsofnetlify.com/',
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
const map1 = new ImportMap([inputFile1, inputFile2]);
|
|
186
|
-
const map2 = map1.clone();
|
|
187
|
-
map2.add({
|
|
188
|
-
baseURL: pathToFileURL(basePath),
|
|
189
|
-
imports: {
|
|
190
|
-
netlify: 'https://netlify.com',
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
expect(map1.getContents()).toStrictEqual({
|
|
194
|
-
imports: {
|
|
195
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy',
|
|
196
|
-
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
|
|
197
|
-
'alias:jamstack': 'https://jamstack.org/',
|
|
198
|
-
'alias:pets': 'https://petsofnetlify.com/',
|
|
199
|
-
},
|
|
200
|
-
scopes: {},
|
|
201
|
-
});
|
|
202
|
-
expect(map2.getContents()).toStrictEqual({
|
|
203
|
-
imports: {
|
|
204
|
-
'netlify:edge': 'https://edge.netlify.com/v1/index.ts?v=legacy',
|
|
205
|
-
'@netlify/edge-functions': 'https://edge.netlify.com/v1/index.ts',
|
|
206
|
-
'alias:jamstack': 'https://jamstack.org/',
|
|
207
|
-
'alias:pets': 'https://petsofnetlify.com/',
|
|
208
|
-
netlify: 'https://netlify.com/',
|
|
209
|
-
},
|
|
210
|
-
scopes: {},
|
|
211
|
-
});
|
|
212
|
-
});
|
package/dist/node/logger.test.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { afterEach, test, expect, vi } from 'vitest';
|
|
2
|
-
import { getLogger } from './logger.js';
|
|
3
|
-
const consoleLog = console.log;
|
|
4
|
-
const noopLogger = () => {
|
|
5
|
-
// no-op
|
|
6
|
-
};
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
// Restoring global `console.log`.
|
|
9
|
-
console.log = consoleLog;
|
|
10
|
-
});
|
|
11
|
-
test('Prints user logs to stdout if no user logger is provided', () => {
|
|
12
|
-
const mockConsoleLog = vi.fn();
|
|
13
|
-
console.log = mockConsoleLog;
|
|
14
|
-
const logger1 = getLogger(noopLogger, undefined, true);
|
|
15
|
-
const logger2 = getLogger(noopLogger, undefined, false);
|
|
16
|
-
logger1.user('Hello with `debug: true`');
|
|
17
|
-
logger2.user('Hello with `debug: false`');
|
|
18
|
-
expect(mockConsoleLog).toHaveBeenCalledTimes(2);
|
|
19
|
-
expect(mockConsoleLog).toHaveBeenNthCalledWith(1, 'Hello with `debug: true`');
|
|
20
|
-
expect(mockConsoleLog).toHaveBeenNthCalledWith(2, 'Hello with `debug: false`');
|
|
21
|
-
});
|
|
22
|
-
test('Prints user logs to user logger provided', () => {
|
|
23
|
-
const userLogger = vi.fn();
|
|
24
|
-
const logger = getLogger(noopLogger, userLogger, true);
|
|
25
|
-
logger.user('Hello!');
|
|
26
|
-
expect(userLogger).toHaveBeenCalledTimes(1);
|
|
27
|
-
expect(userLogger).toHaveBeenNthCalledWith(1, 'Hello!');
|
|
28
|
-
});
|
|
29
|
-
test('Prints system logs to the system logger provided', () => {
|
|
30
|
-
const mockSystemLog = vi.fn();
|
|
31
|
-
const mockConsoleLog = vi.fn();
|
|
32
|
-
console.log = mockSystemLog;
|
|
33
|
-
const logger1 = getLogger(mockSystemLog, undefined, true);
|
|
34
|
-
const logger2 = getLogger(mockSystemLog, undefined, false);
|
|
35
|
-
logger1.system('Hello with `debug: true`');
|
|
36
|
-
logger2.system('Hello with `debug: false`');
|
|
37
|
-
expect(mockConsoleLog).toHaveBeenCalledTimes(0);
|
|
38
|
-
expect(mockSystemLog).toHaveBeenCalledTimes(2);
|
|
39
|
-
expect(mockSystemLog).toHaveBeenNthCalledWith(1, 'Hello with `debug: true`');
|
|
40
|
-
expect(mockSystemLog).toHaveBeenNthCalledWith(2, 'Hello with `debug: false`');
|
|
41
|
-
});
|
|
42
|
-
test('Prints system logs to stdout if there is no system logger provided and `debug` is enabled', () => {
|
|
43
|
-
const mockConsoleLog = vi.fn();
|
|
44
|
-
console.log = mockConsoleLog;
|
|
45
|
-
const logger1 = getLogger(undefined, undefined, true);
|
|
46
|
-
const logger2 = getLogger(undefined, undefined, false);
|
|
47
|
-
logger1.system('Hello with `debug: true`');
|
|
48
|
-
logger2.system('Hello with `debug: false`');
|
|
49
|
-
expect(mockConsoleLog).toHaveBeenCalledTimes(1);
|
|
50
|
-
expect(mockConsoleLog).toHaveBeenNthCalledWith(1, 'Hello with `debug: true`');
|
|
51
|
-
});
|
package/dist/node/main.test.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Buffer } from 'buffer';
|
|
2
|
-
import { rm } from 'fs/promises';
|
|
3
|
-
import { createRequire } from 'module';
|
|
4
|
-
import { platform } from 'process';
|
|
5
|
-
import { PassThrough } from 'stream';
|
|
6
|
-
import nock from 'nock';
|
|
7
|
-
import semver from 'semver';
|
|
8
|
-
import tmp from 'tmp-promise';
|
|
9
|
-
import { test, expect, vi } from 'vitest';
|
|
10
|
-
import { DenoBridge, DENO_VERSION_RANGE } from './bridge.js';
|
|
11
|
-
import { getPlatformTarget } from './platform.js';
|
|
12
|
-
const require = createRequire(import.meta.url);
|
|
13
|
-
const archiver = require('archiver');
|
|
14
|
-
test('Downloads the Deno CLI on demand and caches it for subsequent calls', async () => {
|
|
15
|
-
const latestVersion = semver.minVersion(DENO_VERSION_RANGE)?.version ?? '';
|
|
16
|
-
const mockBinaryOutput = `#!/usr/bin/env sh\n\necho "deno ${latestVersion}"`;
|
|
17
|
-
const data = new PassThrough();
|
|
18
|
-
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
19
|
-
archive.pipe(data);
|
|
20
|
-
archive.append(Buffer.from(mockBinaryOutput), { name: platform === 'win32' ? 'deno.exe' : 'deno' });
|
|
21
|
-
archive.finalize();
|
|
22
|
-
const target = getPlatformTarget();
|
|
23
|
-
const latestReleaseMock = nock('https://dl.deno.land').get('/release-latest.txt').reply(200, `v${latestVersion}`);
|
|
24
|
-
const downloadMock = nock('https://dl.deno.land')
|
|
25
|
-
.get(`/release/v${latestVersion}/deno-${target}.zip`)
|
|
26
|
-
.reply(200, () => data);
|
|
27
|
-
const tmpDir = await tmp.dir();
|
|
28
|
-
const beforeDownload = vi.fn();
|
|
29
|
-
const afterDownload = vi.fn();
|
|
30
|
-
const deno = new DenoBridge({
|
|
31
|
-
cacheDirectory: tmpDir.path,
|
|
32
|
-
onBeforeDownload: beforeDownload,
|
|
33
|
-
onAfterDownload: afterDownload,
|
|
34
|
-
useGlobal: false,
|
|
35
|
-
});
|
|
36
|
-
const output1 = await deno.run(['help']);
|
|
37
|
-
const output2 = await deno.run(['help']);
|
|
38
|
-
const expectedOutput = /^deno [\d.]+/;
|
|
39
|
-
expect(latestReleaseMock.isDone()).toBe(true);
|
|
40
|
-
expect(downloadMock.isDone()).toBe(true);
|
|
41
|
-
expect(output1?.stdout ?? '').toMatch(expectedOutput);
|
|
42
|
-
expect(output2?.stdout ?? '').toMatch(expectedOutput);
|
|
43
|
-
expect(beforeDownload).toHaveBeenCalledTimes(1);
|
|
44
|
-
expect(afterDownload).toHaveBeenCalledTimes(1);
|
|
45
|
-
await rm(tmpDir.path, { force: true, recursive: true, maxRetries: 10 });
|
|
46
|
-
});
|