Skip to content

Commit 6916d9d

Browse files
committed
Add browser entry point
1 parent fb2084c commit 6916d9d

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
// MAIN //
4+
5+
/**
6+
* Changes the current working directory.
7+
*
8+
* ## Notes
9+
*
10+
* - This function assumes the existence of a virtual filesystem in a browser environment.
11+
*
12+
* @param {string} path - desired working directory
13+
* @returns {(Error|null)} error object
14+
*
15+
* @example
16+
* var err = chdir( __dirname );
17+
* if ( err ) {
18+
* throw err;
19+
* }
20+
*/
21+
function chdir( path ) { // eslint-disable-line no-unused-vars
22+
// TODO: implement
23+
return new Error( 'invalid operation. A browser environment has no support for changing the current working directory.' );
24+
}
25+
26+
27+
// EXPORTS //
28+
29+
module.exports = chdir;

lib/node_modules/@stdlib/process/chdir/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
}
1515
],
1616
"main": "./lib",
17+
"browser": "./lib/browser.js",
1718
"directories": {
1819
"benchmark": "./benchmark",
1920
"doc": "./docs",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use strict';
2+
3+
// MODULES //
4+
5+
var tape = require( 'tape' );
6+
var chdir = require( './../lib/browser.js' );
7+
8+
9+
// TESTS //
10+
11+
tape( 'main export is a function', function test( t ) {
12+
t.ok( true, __filename );
13+
t.equal( typeof chdir, 'function', 'main export is a function' );
14+
t.end();
15+
});
16+
17+
tape( 'the function returns an error', function test( t ) {
18+
var err = chdir();
19+
t.equal( err instanceof Error, true, 'returns an error' );
20+
t.end();
21+
});

lib/node_modules/@stdlib/process/chdir/test/test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
var tape = require( 'tape' );
66
var cwd = require( '@stdlib/process/cwd' );
7+
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
78
var chdir = require( './../lib' );
89

910

1011
// VARIABLES //
1112

1213
var DIR = cwd();
14+
var opts = {
15+
'skip': IS_BROWSER
16+
};
1317

1418

1519
// FUNCTIONS //
@@ -26,13 +30,13 @@ function restore() {
2630

2731
// TESTS //
2832

29-
tape( 'main export is a function', function test( t ) {
33+
tape( 'main export is a function', opts, function test( t ) {
3034
t.ok( true, __filename );
3135
t.equal( typeof chdir, 'function', 'main export is a function' );
3236
t.end();
3337
});
3438

35-
tape( 'the function changes the working directory', function test( t ) {
39+
tape( 'the function changes the working directory', opts, function test( t ) {
3640
var err = chdir( __dirname );
3741

3842
t.equal( err, null, 'returns expected value' );
@@ -44,7 +48,7 @@ tape( 'the function changes the working directory', function test( t ) {
4448
t.end();
4549
});
4650

47-
tape( 'if the function encounters an error when attempting to change the working directory, the function returns the error', function test( t ) {
51+
tape( 'if the function encounters an error when attempting to change the working directory, the function returns the error', opts, function test( t ) {
4852
var err = chdir( 'kjflajflsda/bkadlfjadlfksabldjkfklajsf/dkfaljsf' ); // non-existent directory
4953

5054
t.equal( err instanceof Error, true, 'returns an error' );

0 commit comments

Comments
 (0)