Skip to content

Commit 27593f0

Browse files
committed
modify the tests for a synced version
1 parent 602d857 commit 27593f0

File tree

1 file changed

+44
-74
lines changed

1 file changed

+44
-74
lines changed

test/config-file-test.js

+44-74
Original file line numberDiff line numberDiff line change
@@ -37,98 +37,81 @@ describe("ConfigFile", function() {
3737
}
3838
});
3939

40-
it("returns an error", function(done) {
41-
configFile.read(function(err) {
42-
expect(err).to.exist;
43-
expect(err.toString()).to.contain('non-existing-config.js');
44-
done();
45-
});
40+
it("it throws an error if file not found", function() {
41+
var read = function() {
42+
configFile.read();
43+
};
44+
45+
expect(read).to.throw(/non-existing-config\.js/);
4646
});
4747

4848
describe("when createIfNotExists() is used before", function() {
4949
beforeEach(function() {
5050
configFile.createIfNotExists();
5151
});
5252

53-
it("returns a empty config", function(done) {
54-
configFile.read(function(err, config) {
55-
expect(err).to.not.exist;
56-
expect(config).to.exist.and.to.be.a('object').and.to.be.empty;
57-
done();
58-
});
53+
it("returns a empty config", function() {
54+
var config = configFile.read();
55+
expect(config).to.exist.and.to.be.a('object').and.to.be.empty;
5956
});
6057
});
6158
});
6259

6360
describe("with a requirejs.config() call with a define() in the file", function() {
6461
var configFile = new ConfigFile(fixture('config-with-define.js'));
6562

66-
it("returns all the properties in the config", function(done) {
67-
var config = configFile.read(function (err, config) {
68-
expect(err).to.not.exist;
63+
it("returns all the properties in the config", function() {
64+
var config = configFile.read();
6965

70-
expect(config).to.include.keys('paths');
71-
done();
72-
});
66+
expect(config).to.include.keys('paths');
7367
});
7468
});
7569

7670

7771
describe("with a normal requirejs.config() call in the file", function() {
7872
var configFile = new ConfigFile(fixture('normal-config.js'));
7973

80-
it("returns the config as an object", function (done) {
81-
configFile.read(function (err, config) {
82-
expect(err).to.not.exist;
83-
expect(config).to.exist.and.to.be.an.object;
84-
done();
85-
});
74+
it("returns the config as an object", function() {
75+
var config = configFile.read();
76+
expect(config).to.exist.and.to.be.an('object');
8677
});
8778

88-
it("returns all the properties in the config", function(done) {
89-
var config = configFile.read(function (err, config) {
90-
expect(err).to.not.exist;
91-
expect(config).to.include.keys('paths');
92-
done();
93-
});
79+
it("returns all the properties in the config", function() {
80+
var config = configFile.read();
81+
82+
expect(config).to.be.an('object').and.to.include.keys('paths');
9483
});
9584
});
9685

97-
describe("with a var require definition", function () {
86+
describe("with a var require definition", function() {
9887
var configFile = new ConfigFile(fixture('var-config.js'));
9988

100-
it("returns the properties from config", function (done) {
101-
configFile.read(function (err, config) {
102-
expect(err).to.not.exist;
103-
expect(config).to.include.keys('paths');
104-
done();
105-
});
89+
it("returns the properties from config", function() {
90+
var config = configFile.read();
91+
expect(config).to.include.keys('paths');
10692
});
10793
});
10894

10995
describe("with an parse error config", function() {
11096
var configFile = new ConfigFile(fixture('parse-error-config.js'));
11197

112-
it("shows an error", function (done) {
113-
configFile.read(function(err) {
114-
expect(err).to.exist;
115-
expect(err).to.include('syntax error');
116-
done();
117-
});
98+
it("shows an error", function () {
99+
var read = function() {
100+
configFile.read();
101+
};
102+
103+
expect(read).to.throw(/syntax error/);
118104
});
119105
});
120106

121107
describe("with an empty config", function() {
122108
var configFile = new ConfigFile(fixture('empty-config.js'));
123109

124-
it("reads the config file and returns an empty object without notice", function (done) {
125-
configFile.read(function(err, config) {
126-
expect(err).to.not.exist;
127-
expect(config).to.exist.and.to.be.a('object').and.to.be.empty;
128-
done();
129-
});
130-
});
110+
it("reads the config file and returns an empty object without notice", function() {
111+
var config = configFile.read();
131112

113+
expect(config).to.exist.and.to.be.a('object').and.to.be.empty;
114+
});
132115
});
133116
});
134117

@@ -140,21 +123,17 @@ describe("ConfigFile", function() {
140123

141124
var configFile = new ConfigFile(configFilePath);
142125

143-
configFile.read(function (err, config) {
144-
expect(err).to.not.exist;
126+
var config = configFile.read();
145127

146-
modify(config);
128+
modify(config);
147129

148-
configFile.write(function (err) {
149-
expect(err).to.not.exist;
130+
configFile.write();
150131

151-
var expectedContents = fs.readFileSync(fixture('modified-'+configName)).toString();
152-
var actualContents = fs.readFileSync(configFilePath).toString();
132+
var expectedContents = fs.readFileSync(fixture('modified-'+configName)).toString();
133+
var actualContents = fs.readFileSync(configFilePath).toString();
153134

154-
assert.equal(actualContents, expectedContents);
155-
done();
156-
});
157-
});
135+
assert.equal(actualContents, expectedContents);
136+
done();
158137
});
159138
};
160139

@@ -200,26 +179,17 @@ describe("ConfigFile", function() {
200179
}
201180
});
202181

203-
it("writes the file", function(done) {
182+
it("writes the file", function() {
204183
configFile.createIfNotExists();
205-
206-
configFile.write(function (err) {
207-
expect(err).to.not.exist;
208-
done();
209-
});
184+
configFile.write();
210185
});
211186

212-
213-
it("writes the file and creates directories", function(done) {
187+
it("writes the file and creates directories", function() {
214188
var nonExistingFile = tmpPath('in/directory/non-existing-config.js');
215189
var configFile = new ConfigFile(nonExistingFile);
216190

217191
configFile.createIfNotExists();
218-
219-
configFile.write(function (err) {
220-
expect(err).to.not.exist;
221-
done();
222-
});
192+
configFile.write();
223193
});
224194
});
225195
});

0 commit comments

Comments
 (0)