Skip to content

Commit f913a54

Browse files
committed
fix tests
1 parent 59a65e0 commit f913a54

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

test/private-binary.test.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict';
22

33
const fs = require('fs');
4+
const path = require('path');
45
const test = require('tape');
56
const nock = require('nock');
67
const install = require('../lib/install.js');
78

89
// Dummy tar.gz data - contains a blank directory
910
const targz = 'H4sICPr8u1oCA3gudGFyANPTZ6A5MDAwMDc1VQDTZhAaCGA0hGNobGRqZm5uZmxupGBgaGhiZsKgYMpAB1BaXJJYBHRKYk5pcioedeUZqak5+D2J5CkFhlEwCkbBKBjkAAAyG1ofAAYAAA==';
1011

12+
// Determine the project root (where package.json with @mapbox/node-pre-gyp exists)
13+
const projectRoot = path.join(__dirname, '..');
14+
1115
test('should fallback to authenticated download on 403 Forbidden', (t) => {
1216
process.env.node_pre_gyp_mock_s3 = 'true';
1317
process.env.AWS_ACCESS_KEY_ID = 'mock-key';
@@ -28,7 +32,9 @@ test('should fallback to authenticated download on 403 Forbidden', (t) => {
2832
}
2933
};
3034

31-
process.chdir('test/app1');
35+
// cd into app directory from project root
36+
const appDir = path.join(projectRoot, 'test', 'app1');
37+
process.chdir(appDir);
3238
opts.package_json = JSON.parse(fs.readFileSync('./package.json'));
3339
opts.package_json.binary.host = origin;
3440

@@ -51,12 +57,6 @@ test('should fallback to authenticated download on 403 Forbidden', (t) => {
5157
});
5258

5359
test('should fail gracefully when 403 and no AWS credentials', (t) => {
54-
try {
55-
process.chdir('test/app1');
56-
} catch (e) {
57-
// Already in test/app1 from previous test
58-
}
59-
6060
// Ensure no AWS credentials
6161
delete process.env.AWS_ACCESS_KEY_ID;
6262
delete process.env.AWS_SECRET_ACCESS_KEY;
@@ -76,6 +76,9 @@ test('should fail gracefully when 403 and no AWS credentials', (t) => {
7676
}
7777
};
7878

79+
// cd into app directory from project root
80+
const appDir = path.join(projectRoot, 'test', 'app1');
81+
process.chdir(appDir);
7982
opts.package_json = JSON.parse(fs.readFileSync('./package.json'));
8083
opts.package_json.binary.host = origin;
8184

@@ -91,12 +94,6 @@ test('should fail gracefully when 403 and no AWS credentials', (t) => {
9194
});
9295

9396
test('should succeed with public binary (no 403)', (t) => {
94-
try {
95-
process.chdir('test/app1');
96-
} catch (e) {
97-
// Already in test/app1
98-
}
99-
10097
const origin = 'https://npg-mock-bucket.s3.us-east-1.amazonaws.com';
10198
nock.cleanAll();
10299
const scope = nock(origin)
@@ -110,6 +107,9 @@ test('should succeed with public binary (no 403)', (t) => {
110107
}
111108
};
112109

110+
// cd into app directory from project root
111+
const appDir = path.join(projectRoot, 'test', 'app1');
112+
process.chdir(appDir);
113113
opts.package_json = JSON.parse(fs.readFileSync('./package.json'));
114114
opts.package_json.binary.host = origin;
115115

@@ -123,12 +123,6 @@ test('should succeed with public binary (no 403)', (t) => {
123123
});
124124

125125
test('should handle 404 without triggering authenticated fallback', (t) => {
126-
try {
127-
process.chdir('test/app1');
128-
} catch (e) {
129-
// Already in test/app1
130-
}
131-
132126
const origin = 'https://npg-mock-bucket.s3.us-east-1.amazonaws.com';
133127

134128
nock.cleanAll();
@@ -143,6 +137,9 @@ test('should handle 404 without triggering authenticated fallback', (t) => {
143137
}
144138
};
145139

140+
// cd into app directory from project root
141+
const appDir = path.join(projectRoot, 'test', 'app1');
142+
process.chdir(appDir);
146143
opts.package_json = JSON.parse(fs.readFileSync('./package.json'));
147144
opts.package_json.binary.host = origin;
148145

0 commit comments

Comments
 (0)