2024-01-01 19:58:21 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-13 07:51:32 +00:00
|
|
|
|
2020-06-11 16:36:20 +00:00
|
|
|
import {
|
|
|
|
assert,
|
|
|
|
assertEquals,
|
2021-09-22 13:21:11 +00:00
|
|
|
assertRejects,
|
2020-06-24 22:57:08 +00:00
|
|
|
assertThrows,
|
2020-06-11 16:36:20 +00:00
|
|
|
pathToAbsoluteFileUrl,
|
2021-12-16 11:57:26 +00:00
|
|
|
unreachable,
|
2020-06-11 16:36:20 +00:00
|
|
|
} from "./test_util.ts";
|
2020-04-28 05:35:20 +00:00
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: true } }, function readTextFileSyncSuccess() {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
const data = Deno.readTextFileSync("tests/testdata/assets/fixture.json");
|
2020-04-28 05:35:20 +00:00
|
|
|
assert(data.length > 0);
|
|
|
|
const pkg = JSON.parse(data);
|
|
|
|
assertEquals(pkg.name, "deno");
|
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: true } }, function readTextFileSyncByUrl() {
|
2020-06-11 16:36:20 +00:00
|
|
|
const data = Deno.readTextFileSync(
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
pathToAbsoluteFileUrl("tests/testdata/assets/fixture.json"),
|
2020-06-11 16:36:20 +00:00
|
|
|
);
|
|
|
|
assert(data.length > 0);
|
|
|
|
const pkg = JSON.parse(data);
|
|
|
|
assertEquals(pkg.name, "deno");
|
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: false } }, function readTextFileSyncPerm() {
|
2020-06-24 22:57:08 +00:00
|
|
|
assertThrows(() => {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
Deno.readTextFileSync("tests/testdata/assets/fixture.json");
|
2020-06-24 22:57:08 +00:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2020-04-28 05:35:20 +00:00
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: true } }, function readTextFileSyncNotFound() {
|
2020-06-24 22:57:08 +00:00
|
|
|
assertThrows(() => {
|
|
|
|
Deno.readTextFileSync("bad_filename");
|
|
|
|
}, Deno.errors.NotFound);
|
2020-04-28 05:35:20 +00:00
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test(
|
2021-09-22 23:50:50 +00:00
|
|
|
{ permissions: { read: true } },
|
2021-08-05 11:08:58 +00:00
|
|
|
async function readTextFileSuccess() {
|
2022-09-19 14:32:21 +00:00
|
|
|
const data = await Deno.readTextFile(
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
"tests/testdata/assets/fixture.json",
|
2022-09-19 14:32:21 +00:00
|
|
|
);
|
2020-04-28 05:35:20 +00:00
|
|
|
assert(data.length > 0);
|
|
|
|
const pkg = JSON.parse(data);
|
|
|
|
assertEquals(pkg.name, "deno");
|
2020-07-14 19:24:17 +00:00
|
|
|
},
|
2020-04-28 05:35:20 +00:00
|
|
|
);
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: true } }, async function readTextFileByUrl() {
|
2020-06-11 16:36:20 +00:00
|
|
|
const data = await Deno.readTextFile(
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
pathToAbsoluteFileUrl("tests/testdata/assets/fixture.json"),
|
2020-06-11 16:36:20 +00:00
|
|
|
);
|
|
|
|
assert(data.length > 0);
|
|
|
|
const pkg = JSON.parse(data);
|
|
|
|
assertEquals(pkg.name, "deno");
|
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: false } }, async function readTextFilePerm() {
|
2021-09-22 13:21:11 +00:00
|
|
|
await assertRejects(async () => {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
await Deno.readTextFile("tests/testdata/assets/fixture.json");
|
2020-06-24 22:57:08 +00:00
|
|
|
}, Deno.errors.PermissionDenied);
|
2020-04-28 05:35:20 +00:00
|
|
|
});
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test({ permissions: { read: true } }, function readTextFileSyncLoop() {
|
2020-04-28 05:35:20 +00:00
|
|
|
for (let i = 0; i < 256; i++) {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
Deno.readTextFileSync("tests/testdata/assets/fixture.json");
|
2020-04-28 05:35:20 +00:00
|
|
|
}
|
|
|
|
});
|
2021-04-08 14:36:52 +00:00
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test(
|
2021-09-22 23:50:50 +00:00
|
|
|
{ permissions: { read: true } },
|
2021-08-05 11:08:58 +00:00
|
|
|
async function readTextFileDoesNotLeakResources() {
|
2021-09-22 13:21:11 +00:00
|
|
|
await assertRejects(async () => await Deno.readTextFile("cli"));
|
2021-04-08 14:36:52 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test(
|
2021-09-22 23:50:50 +00:00
|
|
|
{ permissions: { read: true } },
|
2021-08-05 11:08:58 +00:00
|
|
|
function readTextFileSyncDoesNotLeakResources() {
|
2021-04-08 14:36:52 +00:00
|
|
|
assertThrows(() => Deno.readTextFileSync("cli"));
|
|
|
|
},
|
|
|
|
);
|
2021-11-22 15:53:58 +00:00
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test(
|
2021-11-22 15:53:58 +00:00
|
|
|
{ permissions: { read: true } },
|
|
|
|
async function readTextFileWithAbortSignal() {
|
|
|
|
const ac = new AbortController();
|
|
|
|
queueMicrotask(() => ac.abort());
|
2022-10-17 22:57:31 +00:00
|
|
|
const error = await assertRejects(
|
2021-12-16 11:57:26 +00:00
|
|
|
async () => {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
await Deno.readTextFile("tests/testdata/assets/fixture.json", {
|
2021-12-16 11:57:26 +00:00
|
|
|
signal: ac.signal,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2022-10-17 22:57:31 +00:00
|
|
|
assert(error instanceof DOMException);
|
|
|
|
assertEquals(error.name, "AbortError");
|
2021-12-16 11:57:26 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true } },
|
|
|
|
async function readTextFileWithAbortSignalReason() {
|
|
|
|
const ac = new AbortController();
|
|
|
|
const abortReason = new Error();
|
|
|
|
queueMicrotask(() => ac.abort(abortReason));
|
2022-10-17 22:57:31 +00:00
|
|
|
const error = await assertRejects(
|
2021-12-16 11:57:26 +00:00
|
|
|
async () => {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
await Deno.readTextFile("tests/testdata/assets/fixture.json", {
|
2021-12-16 11:57:26 +00:00
|
|
|
signal: ac.signal,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2022-10-17 22:57:31 +00:00
|
|
|
assertEquals(error, abortReason);
|
2021-12-16 11:57:26 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true } },
|
|
|
|
async function readTextFileWithAbortSignalPrimitiveReason() {
|
|
|
|
const ac = new AbortController();
|
|
|
|
queueMicrotask(() => ac.abort("Some string"));
|
|
|
|
try {
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
await Deno.readTextFile("tests/testdata/assets/fixture.json", {
|
2021-11-22 15:53:58 +00:00
|
|
|
signal: ac.signal,
|
|
|
|
});
|
2021-12-16 11:57:26 +00:00
|
|
|
unreachable();
|
|
|
|
} catch (e) {
|
|
|
|
assertEquals(e, "Some string");
|
|
|
|
}
|
2021-11-22 15:53:58 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-02-11 12:19:13 +00:00
|
|
|
// Test that AbortController's cancel handle is cleaned-up correctly, and do not leak resources.
|
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true } },
|
|
|
|
async function readTextFileWithAbortSignalNotCalled() {
|
|
|
|
const ac = new AbortController();
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
await Deno.readTextFile("tests/testdata/assets/fixture.json", {
|
2023-02-11 12:19:13 +00:00
|
|
|
signal: ac.signal,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2021-11-23 16:45:18 +00:00
|
|
|
Deno.test(
|
2021-11-22 15:53:58 +00:00
|
|
|
{ permissions: { read: true }, ignore: Deno.build.os !== "linux" },
|
|
|
|
async function readTextFileProcFs() {
|
|
|
|
const data = await Deno.readTextFile("/proc/self/stat");
|
|
|
|
assert(data.length > 0);
|
|
|
|
},
|
|
|
|
);
|
2022-09-01 20:20:11 +00:00
|
|
|
|
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true, write: true } },
|
|
|
|
function readTextFileSyncV8LimitError() {
|
|
|
|
const kStringMaxLengthPlusOne = 536870888 + 1;
|
|
|
|
const bytes = new Uint8Array(kStringMaxLengthPlusOne);
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
const filePath = "tests/testdata/too_big_a_file.txt";
|
2022-09-01 20:20:11 +00:00
|
|
|
|
2023-04-27 22:37:03 +00:00
|
|
|
try {
|
|
|
|
Deno.writeFileSync(filePath, bytes);
|
|
|
|
} catch {
|
|
|
|
// NOTE(bartlomieju): writing a 0.5Gb file might be too much for CI,
|
|
|
|
// so skip running if writing fails.
|
|
|
|
return;
|
|
|
|
}
|
2022-09-01 20:20:11 +00:00
|
|
|
|
|
|
|
assertThrows(
|
|
|
|
() => {
|
|
|
|
Deno.readTextFileSync(filePath);
|
|
|
|
},
|
|
|
|
TypeError,
|
|
|
|
"buffer exceeds maximum length",
|
|
|
|
);
|
|
|
|
|
|
|
|
Deno.removeSync(filePath);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
Deno.test(
|
|
|
|
{ permissions: { read: true, write: true } },
|
|
|
|
async function readTextFileV8LimitError() {
|
|
|
|
const kStringMaxLengthPlusOne = 536870888 + 1;
|
|
|
|
const bytes = new Uint8Array(kStringMaxLengthPlusOne);
|
chore: move cli/tests/ -> tests/ (#22369)
This looks like a massive PR, but it's only a move from cli/tests ->
tests, and updates of relative paths for files.
This is the first step towards aggregate all of the integration test
files under tests/, which will lead to a set of integration tests that
can run without the CLI binary being built.
While we could leave these tests under `cli`, it would require us to
keep a more complex directory structure for the various test runners. In
addition, we have a lot of complexity to ignore various test files in
the `cli` project itself (cargo publish exclusion rules, autotests =
false, etc).
And finally, the `tests/` folder will eventually house the `test_ffi`,
`test_napi` and other testing code, reducing the size of the root repo
directory.
For easier review, the extremely large and noisy "move" is in the first
commit (with no changes -- just a move), while the remainder of the
changes to actual files is in the second commit.
2024-02-10 20:22:13 +00:00
|
|
|
const filePath = "tests/testdata/too_big_a_file_2.txt";
|
2022-09-01 20:20:11 +00:00
|
|
|
|
2023-04-27 22:37:03 +00:00
|
|
|
try {
|
|
|
|
await Deno.writeFile(filePath, bytes);
|
|
|
|
} catch {
|
|
|
|
// NOTE(bartlomieju): writing a 0.5Gb file might be too much for CI,
|
|
|
|
// so skip running if writing fails.
|
|
|
|
return;
|
|
|
|
}
|
2022-09-01 20:20:11 +00:00
|
|
|
|
|
|
|
await assertRejects(
|
|
|
|
async () => {
|
|
|
|
await Deno.readTextFile(filePath);
|
|
|
|
},
|
|
|
|
TypeError,
|
|
|
|
"buffer exceeds maximum length",
|
|
|
|
);
|
|
|
|
|
|
|
|
await Deno.remove(filePath);
|
|
|
|
},
|
|
|
|
);
|