Skip to content

Commit 83d6c09

Browse files
authored
Decaffeinate specs (atom#21546)
Decaffeinate the following files. * atom-protocol-handler * babel-spec * buffered-node-process * buffered-process * clipboard * context-menu-manager * decoration-manager * default-directory-provider * deserializer-manager * file-system-blob-store * keymap-extensions * menu-manager * module-cache * pane-axis-element * pane-container-element * pane-element * package-spec * squirel-update * styles-element-spec * task-spec * typescript-spec * spec-helper-platform
1 parent d600556 commit 83d6c09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+3129
-2412
lines changed

spec/atom-protocol-handler-spec.coffee

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/atom-protocol-handler-spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
describe('"atom" protocol URL', () =>
2+
it('sends the file relative in the package as response', function() {
3+
let called = false;
4+
const request = new XMLHttpRequest();
5+
request.addEventListener('load', () => (called = true));
6+
request.open('GET', 'atom://async/package.json', true);
7+
request.send();
8+
9+
waitsFor('request to be done', () => called === true);
10+
}));

spec/babel-spec.coffee

Lines changed: 0 additions & 62 deletions
This file was deleted.

spec/babel-spec.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Users may have this environment variable set. Currently, it causes babel to
2+
// log to stderr, which causes errors on Windows.
3+
// See https://github.com/atom/electron/issues/2033
4+
process.env.DEBUG = '*';
5+
6+
const path = require('path');
7+
const temp = require('temp').track();
8+
const CompileCache = require('../src/compile-cache');
9+
10+
describe('Babel transpiler support', function() {
11+
let originalCacheDir = null;
12+
13+
beforeEach(function() {
14+
originalCacheDir = CompileCache.getCacheDirectory();
15+
CompileCache.setCacheDirectory(temp.mkdirSync('compile-cache'));
16+
// TODO: rework to avoid using IIFE https://developer.mozilla.org/en-US/docs/Glossary/IIFE
17+
return (() => {
18+
const result = [];
19+
for (let cacheKey of Object.keys(require.cache)) {
20+
if (cacheKey.startsWith(path.join(__dirname, 'fixtures', 'babel'))) {
21+
result.push(delete require.cache[cacheKey]);
22+
} else {
23+
result.push(undefined);
24+
}
25+
}
26+
return result;
27+
})();
28+
});
29+
30+
afterEach(function() {
31+
CompileCache.setCacheDirectory(originalCacheDir);
32+
try {
33+
return temp.cleanupSync();
34+
} catch (error) {}
35+
});
36+
37+
describe('when a .js file starts with /** @babel */;', () =>
38+
it('transpiles it using babel', function() {
39+
const transpiled = require('./fixtures/babel/babel-comment.js');
40+
expect(transpiled(3)).toBe(4);
41+
}));
42+
43+
describe("when a .js file starts with 'use babel';", () =>
44+
it('transpiles it using babel', function() {
45+
const transpiled = require('./fixtures/babel/babel-single-quotes.js');
46+
expect(transpiled(3)).toBe(4);
47+
}));
48+
49+
describe('when a .js file starts with "use babel";', () =>
50+
it('transpiles it using babel', function() {
51+
const transpiled = require('./fixtures/babel/babel-double-quotes.js');
52+
expect(transpiled(3)).toBe(4);
53+
}));
54+
55+
describe('when a .js file starts with /* @flow */', () =>
56+
it('transpiles it using babel', function() {
57+
const transpiled = require('./fixtures/babel/flow-comment.js');
58+
expect(transpiled(3)).toBe(4);
59+
}));
60+
61+
describe('when a .js file starts with // @flow', () =>
62+
it('transpiles it using babel', function() {
63+
const transpiled = require('./fixtures/babel/flow-slash-comment.js');
64+
expect(transpiled(3)).toBe(4);
65+
}));
66+
67+
describe("when a .js file does not start with 'use babel';", function() {
68+
it('does not transpile it using babel', function() {
69+
spyOn(console, 'error');
70+
expect(() => require('./fixtures/babel/invalid.js')).toThrow();
71+
});
72+
73+
it('does not try to log to stdout or stderr while parsing the file', function() {
74+
spyOn(process.stderr, 'write');
75+
spyOn(process.stdout, 'write');
76+
77+
require('./fixtures/babel/babel-double-quotes.js');
78+
79+
expect(process.stdout.write).not.toHaveBeenCalled();
80+
expect(process.stderr.write).not.toHaveBeenCalled();
81+
});
82+
});
83+
});

spec/buffered-node-process-spec.coffee

Lines changed: 0 additions & 39 deletions
This file was deleted.

spec/buffered-node-process-spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable no-new */
2+
const path = require('path');
3+
const BufferedNodeProcess = require('../src/buffered-node-process');
4+
5+
describe('BufferedNodeProcess', function() {
6+
it('executes the script in a new process', function() {
7+
const exit = jasmine.createSpy('exitCallback');
8+
let output = '';
9+
const stdout = lines => (output += lines);
10+
let error = '';
11+
const stderr = lines => (error += lines);
12+
const args = ['hi'];
13+
const command = path.join(__dirname, 'fixtures', 'script.js');
14+
15+
new BufferedNodeProcess({ command, args, stdout, stderr, exit });
16+
17+
waitsFor(() => exit.callCount === 1);
18+
19+
runs(function() {
20+
expect(output).toBe('hi');
21+
expect(error).toBe('');
22+
expect(args).toEqual(['hi']);
23+
});
24+
});
25+
26+
it('suppresses deprecations in the new process', function() {
27+
const exit = jasmine.createSpy('exitCallback');
28+
let output = '';
29+
const stdout = lines => (output += lines);
30+
let error = '';
31+
const stderr = lines => (error += lines);
32+
const command = path.join(
33+
__dirname,
34+
'fixtures',
35+
'script-with-deprecations.js'
36+
);
37+
38+
new BufferedNodeProcess({ command, stdout, stderr, exit });
39+
40+
waitsFor(() => exit.callCount === 1);
41+
42+
runs(function() {
43+
expect(output).toBe('hi');
44+
expect(error).toBe('');
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)