scratch-storage 2.0.2 → 2.2.0
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/.circleci/config.yml +70 -0
- package/.nyc_output/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +1 -0
- package/.nyc_output/ec2d52a1-5131-4dd0-9c23-59106f297082.json +1 -0
- package/.nyc_output/processinfo/c826ae6b-4ae2-4d8e-bdb2-162df5761fa7.json +1 -0
- package/.nyc_output/processinfo/ec2d52a1-5131-4dd0-9c23-59106f297082.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/README.md +2 -1
- package/dist/node/8c63ecb0448dfbb8e804.worker.js +4187 -0
- package/dist/node/8c63ecb0448dfbb8e804.worker.js.map +1 -0
- package/dist/node/scratch-storage.js +2933 -142
- package/dist/node/scratch-storage.js.map +1 -1
- package/dist/web/90c5db0dff5ca2a36ff6.worker.js +743 -0
- package/dist/web/90c5db0dff5ca2a36ff6.worker.js.map +1 -0
- package/dist/web/scratch-storage.js +1149 -85
- package/dist/web/scratch-storage.js.map +1 -1
- package/dist/web/scratch-storage.min.js +1149 -85
- package/dist/web/scratch-storage.min.js.map +1 -1
- package/package.json +9 -4
- package/src/FetchTool.js +17 -13
- package/src/FetchWorkerTool.js +14 -7
- package/src/FetchWorkerTool.worker.js +6 -10
- package/src/scratchFetch.js +86 -0
- package/test/integration/download-known-assets.js +27 -30
- package/test/mocks/mockFetch.js +64 -0
- package/test/unit/fetch-tool.js +27 -44
- package/test/unit/metadata.js +136 -0
- package/webpack.config.js +9 -8
- package/.travis.yml +0 -24
- package/dist/node/f98711f696b187f5e007.worker.js +0 -1906
- package/dist/node/f98711f696b187f5e007.worker.js.map +0 -1
- package/dist/web/01b4fbd4d14a4f22cab8.worker.js +0 -190
- package/dist/web/01b4fbd4d14a4f22cab8.worker.js.map +0 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
const tap = require('tap');
|
|
2
|
+
|
|
3
|
+
const crossFetch = require('cross-fetch');
|
|
4
|
+
|
|
5
|
+
const {mockFetch} = require('../mocks/mockFetch.js');
|
|
6
|
+
|
|
7
|
+
const mockFetchModule = {
|
|
8
|
+
...crossFetch, // Headers, Request, Response, etc.
|
|
9
|
+
default: mockFetch,
|
|
10
|
+
fetch: mockFetch
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// Call this separately from each test to ensure that metadata gets reset.
|
|
14
|
+
// This is especially important when parallelizing tests!
|
|
15
|
+
const setupModules = () => {
|
|
16
|
+
/**
|
|
17
|
+
* This instance of scratchFetch will be shared between this file and FetchTool.
|
|
18
|
+
* By sharing the same instance, the test can affect the metadata that FetchTool will use.
|
|
19
|
+
*/
|
|
20
|
+
const scratchFetchModule = tap.mock('../../src/scratchFetch', {
|
|
21
|
+
'cross-fetch': mockFetchModule
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* This is the real FetchTool, but the 'cross-fetch' module has been replaced with the mockFetch function.
|
|
26
|
+
* @type {typeof import('../../src/FetchTool')}
|
|
27
|
+
*/
|
|
28
|
+
const FetchTool = tap.mock('../../src/FetchTool', {
|
|
29
|
+
'cross-fetch': mockFetchModule,
|
|
30
|
+
// Make sure FetchTool uses the same scratchFetch instance
|
|
31
|
+
'../../src/scratchFetch': scratchFetchModule
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return {scratchFetchModule, FetchTool};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
tap.test('get without metadata', async t => {
|
|
38
|
+
const {FetchTool} = setupModules();
|
|
39
|
+
|
|
40
|
+
const tool = new FetchTool();
|
|
41
|
+
|
|
42
|
+
/** @type import('../mocks/mockFetch.js').MockFetchTestData */
|
|
43
|
+
const mockFetchTestData = {};
|
|
44
|
+
const result = await tool.get({url: '200', mockFetchTestData});
|
|
45
|
+
|
|
46
|
+
t.type(result, Uint8Array);
|
|
47
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
48
|
+
t.equal(mockFetchTestData.headersCount, 0);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
tap.test('get with metadata', async t => {
|
|
52
|
+
const {scratchFetchModule, FetchTool} = setupModules();
|
|
53
|
+
const {RequestMetadata, setMetadata} = scratchFetchModule;
|
|
54
|
+
|
|
55
|
+
const tool = new FetchTool();
|
|
56
|
+
|
|
57
|
+
setMetadata(RequestMetadata.ProjectId, 1234);
|
|
58
|
+
setMetadata(RequestMetadata.RunId, 5678);
|
|
59
|
+
|
|
60
|
+
/** @type import('../mocks/mockFetch.js').MockFetchTestData */
|
|
61
|
+
const mockFetchTestData = {};
|
|
62
|
+
const result = await tool.get({url: '200', mockFetchTestData});
|
|
63
|
+
|
|
64
|
+
t.type(result, Uint8Array);
|
|
65
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
66
|
+
t.equal(mockFetchTestData.headersCount, 2);
|
|
67
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.ProjectId), '1234');
|
|
68
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.RunId), '5678');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
tap.test('send without metadata', async t => {
|
|
72
|
+
const {FetchTool} = setupModules();
|
|
73
|
+
|
|
74
|
+
const tool = new FetchTool();
|
|
75
|
+
|
|
76
|
+
/** @type import('../mocks/mockFetch.js').MockFetchTestData */
|
|
77
|
+
const mockFetchTestData = {};
|
|
78
|
+
const result = await tool.send({url: '200', mockFetchTestData});
|
|
79
|
+
|
|
80
|
+
t.type(result, 'string');
|
|
81
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
82
|
+
t.equal(mockFetchTestData.headersCount, 0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
tap.test('send with metadata', async t => {
|
|
86
|
+
const {scratchFetchModule, FetchTool} = setupModules();
|
|
87
|
+
const {RequestMetadata, setMetadata} = scratchFetchModule;
|
|
88
|
+
|
|
89
|
+
const tool = new FetchTool();
|
|
90
|
+
|
|
91
|
+
setMetadata(RequestMetadata.ProjectId, 4321);
|
|
92
|
+
setMetadata(RequestMetadata.RunId, 8765);
|
|
93
|
+
|
|
94
|
+
/** @type import('../mocks/mockFetch.js').MockFetchTestData */
|
|
95
|
+
const mockFetchTestData = {};
|
|
96
|
+
const result = await tool.send({url: '200', mockFetchTestData});
|
|
97
|
+
|
|
98
|
+
t.type(result, 'string');
|
|
99
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
100
|
+
t.equal(mockFetchTestData.headersCount, 2);
|
|
101
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.ProjectId), '4321');
|
|
102
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.RunId), '8765');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
tap.test('selectively delete metadata', async t => {
|
|
106
|
+
const {scratchFetchModule, FetchTool} = setupModules();
|
|
107
|
+
const {RequestMetadata, setMetadata, unsetMetadata} = scratchFetchModule;
|
|
108
|
+
|
|
109
|
+
// verify that these special values are preserved and not interpreted as "delete"
|
|
110
|
+
setMetadata(RequestMetadata.ProjectId, null);
|
|
111
|
+
setMetadata(RequestMetadata.RunId, void 0); // void 0 = undefined
|
|
112
|
+
|
|
113
|
+
const tool = new FetchTool();
|
|
114
|
+
|
|
115
|
+
/** @type import('../mocks/mockFetch.js').MockFetchTestData */
|
|
116
|
+
const mockFetchTestData = {};
|
|
117
|
+
|
|
118
|
+
const result1 = await tool.send({url: '200', mockFetchTestData});
|
|
119
|
+
t.type(result1, 'string');
|
|
120
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
121
|
+
|
|
122
|
+
t.equal(mockFetchTestData.headersCount, 2);
|
|
123
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.ProjectId), 'null'); // string "null" means it's present
|
|
124
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.RunId), 'undefined');
|
|
125
|
+
|
|
126
|
+
// remove the Project ID from metadata
|
|
127
|
+
unsetMetadata(RequestMetadata.ProjectId);
|
|
128
|
+
|
|
129
|
+
const result2 = await tool.send({url: '200', mockFetchTestData});
|
|
130
|
+
t.type(result2, 'string');
|
|
131
|
+
t.ok(mockFetchTestData.headers, 'mockFetch did not report headers');
|
|
132
|
+
|
|
133
|
+
t.equal(mockFetchTestData.headersCount, 1);
|
|
134
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.ProjectId), null); // value `null` means it's missing
|
|
135
|
+
t.equal(mockFetchTestData.headers?.get(RequestMetadata.RunId), 'undefined');
|
|
136
|
+
});
|
package/webpack.config.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
|
-
const {ProvidePlugin} = require('webpack');
|
|
3
2
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
|
4
3
|
|
|
5
4
|
const base = {
|
|
@@ -14,9 +13,16 @@ const base = {
|
|
|
14
13
|
test: /\.js$/,
|
|
15
14
|
loader: 'babel-loader',
|
|
16
15
|
options: {
|
|
16
|
+
plugins: [
|
|
17
|
+
'@babel/plugin-transform-runtime'
|
|
18
|
+
],
|
|
17
19
|
presets: [
|
|
18
20
|
['@babel/preset-env', {targets: {browsers: ['last 3 versions', 'Safari >= 8', 'iOS >= 8']}}]
|
|
19
|
-
]
|
|
21
|
+
],
|
|
22
|
+
// Consider a file a "module" if import/export statements are present, or else consider it a
|
|
23
|
+
// "script". Fixes "Cannot assign to read only property 'exports'" when using
|
|
24
|
+
// @babel/plugin-transform-runtime with CommonJS files.
|
|
25
|
+
sourceType: 'unambiguous'
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
]
|
|
@@ -65,11 +71,6 @@ module.exports = [
|
|
|
65
71
|
'js-md5': true,
|
|
66
72
|
'localforage': true,
|
|
67
73
|
'text-encoding': true
|
|
68
|
-
}
|
|
69
|
-
plugins: [
|
|
70
|
-
new ProvidePlugin({
|
|
71
|
-
fetch: ['node-fetch', 'default']
|
|
72
|
-
})
|
|
73
|
-
]
|
|
74
|
+
}
|
|
74
75
|
})
|
|
75
76
|
];
|
package/.travis.yml
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
sudo: false
|
|
2
|
-
language: node_js
|
|
3
|
-
cache:
|
|
4
|
-
directories:
|
|
5
|
-
- node_modules
|
|
6
|
-
node_js:
|
|
7
|
-
- "10"
|
|
8
|
-
install:
|
|
9
|
-
- npm install
|
|
10
|
-
- npm update
|
|
11
|
-
- npm prune
|
|
12
|
-
script:
|
|
13
|
-
- commitlint-travis
|
|
14
|
-
- npm run lint
|
|
15
|
-
- npm run build
|
|
16
|
-
- npm run tap
|
|
17
|
-
deploy:
|
|
18
|
-
- provider: script
|
|
19
|
-
on:
|
|
20
|
-
branch:
|
|
21
|
-
- master
|
|
22
|
-
- develop
|
|
23
|
-
skip_cleanup: true
|
|
24
|
-
script: npm run semantic-release
|